如果您嵌套了JSON,则只需调用
JSONObjectWithData两次:
NSString *string = @""{ \"name\" : \"Bob\", \"age\" : 21 }"";// --> the string// "{ "name" : "Bob", "age" : 21 }"NSError *error;NSString *outerJson = [NSJSonSerialization JSONObjectWithdata:[string dataUsingEncoding:NSUTF8StringEncoding] options:NSJSonReadingAllowFragments error:&error];// --> the string// { "name" : "Bob", "age" : 21 }NSDictionary *innerJson = [NSJSonSerialization JSONObjectWithdata:[outerJson dataUsingEncoding:NSUTF8StringEncoding] options:0 error:&error];// --> the dictionary// { age = 21; name = Bob; }


