0
我有一些奇怪的解析问题与NSMutableDictionary和Alomafire json响应。swift NSMutableDictionary解析json失败
Alamofire.request(.POST, "\(Constants.apiUrl)/get_stuff", parameters: mapData, encoding:.JSON)
.responseJSON { response in
switch response.result {
case .Success(let data):
let info = data as! NSMutableDictionary
self.deleteCategoryFromCoreData()
if let categoryArray = info["category"] as? NSArray{
for var i = 0; i < categoryArray.count; i++ {
self.categoryID = categoryArray[i]["id"] as? Int <-- error here
self.categoryName = categoryArray[i]["name"] as? NSString
self.saveCategoryDataToCoreData()
}
}
我不知道为什么失败:
(lldb) po categoryArray[i]["id"]
2016-05-23 20:59:56.892 MyProject[9799:5005782] -[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000013
error: Execution was interrupted, reason: internal ObjC exception breakpoint(-3)..
The process has been returned to the state before expression evaluation.
但这并不失败:
(lldb) po categoryArray[i]["name"]
▿ Optional<String>
- Some : "Animals"
下面是数据:
(lldb) po categoryArray[i]
▿ 2 elements
▿ [0] : 2 elements
- .0 : id
▿ [1] : 2 elements
- .0 : name
- .1 : Animals
为什么不能我访问“id”键?我无法像这样解析json?我被告知要尝试SwiftyJSON,这种方式根本不可能。所有这些问题发生在我更新到xcode 7.3和cocoapods 1.0.0之后。谢谢。请帮忙 ?