我收到一个JSON对象,如下所示:
{"data":null,
"error":1,
"error_code":"InvalidSID",
"sid":"",
"num_rows_total":0,
"last_insert_id":0,
"error_info":"Comment...",
"error_data":[]}和使用以下代码的JSONKit:
NSString *responseString = [request responseString];
NSDictionary *requestDictionary = [responseString objectFromJSONString];
if([[requestDictionary objectForKey:@"error"] intValue]) {
if([@"InvalidSID" isEqualToString:[requestDictionary objectForKey:@"error_code"]]) {
[self.navigationController popViewControllerAnimated:YES];
}
}产生这样的输出:
{
data = "<null>";
error = 1;
"error_code" = InvalidSID;
"error_data" = ();
"error_info" = "Comment...";
"last_insert_id" = 0;
"num_rows_total" = 0;
sid = "";
}问题是,由于InvalidSID两边缺少引号,因此从未调用过此if语句。有没有什么已知的JSONKit问题会让这些引号消失?
发布于 2012-08-03 21:23:08
您将NSDictionary的"description“输出与键的值混淆了。你也可以通过一些简单的侦探工作为自己节省很多时间(也就是你发布这篇文章的时间,然后你就会得到一些回应)。
我假设您上面所说的“输出”是
NSLog(@"%@", requestDictionary);所以在这一行之后,试试这个:
// Just to be complete
id ee = [requestDictionary objectForKey:@"error"];
NSLog(@"error=%@ intValueOfError=%d classOfErrorCode=%@",
ee, [ee intValue], NSStringFromClass([ee class]) );
// Where I suspect you may discover something
id ec = [requestDictionary objectForKey:@"error_code"];
NSLog(@"errorCode=%@ classOfErrorCode=%@",
ec, NSStringFromClass([ec class]) );我们这样做是因为这里有明显的错误,我们想要了解更多关于我们手中的对象的信息。我猜如果你做了上面的事情,你会发现一些你意想不到的东西。
https://stackoverflow.com/questions/11795328
复制相似问题