我想获得字典表单JSON,但下面的代码剂量似乎工作。我得到了JSON,但无法从中得到字典。从JSON获取字典
NSString *str = [[NSMutableString alloc] initWithData:responseCust encoding:NSUTF8StringEncoding];
NSLog(@"CUSTOMER string -----################ %@", str);
if(str.length>5)
{
SBJSON *jsonparser=[[SBJSON alloc]init];
NSDictionary *res= [jsonparser objectWithString:str];
NSLog(@"Contants Results %@",res);
[jsonparser release];
[str release];
}
谢谢。
使用NSJSONSerialization。 –
请更好地解释你自己。你会得到一个(显然是有效的)JSON字符串,但“Contants Results”打印出“(null)”?如果是这样,请先将JSON复制/粘贴到联机JSON解析器中以检查其有效性。 –
阅读https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html –