我正在尝试从 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];
}
谢谢。
最佳答案
请按照下面的代码
NSURL * url=[NSURL URLWithString:str];
NSData * data=[NSData dataWithContentsOfURL:url];
NSError * error;
//Get json data in Dictionary
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error: &error];
NSLog(@"%@",json);
试试这个..
关于ios - 从 JSON 获取字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18636113/