我有一个NSString "[{"van" : 1,312, "vuan":12,123}]
并且为了获得每个键的这个值,我这样做:
NSData *data1 = [jsonResponse1 dataUsingEncoding:NSUTF8StringEncoding];
jsonArray = [NSJSONSerialization JSONObjectWithData:data1 options:kNilOptions error:&err];
self.van = [NSMutableArray arrayWithCapacity:1];
self.vuan = [NSMutableArray arrayWithCapacity:1];
for (NSDictionary *json in jsonArray) {
NSString * value = [json objectForKey:@"van"];
[self.van addObject:value];
lbl1.text = value;
NSString * value1 = [json objectForKey:@"vuan"];
[self.vuan addObject:value1];
lbl4.text = value1;
}
可能我不必使用数组,而是NSData
直接在NSDictionary
.
无论如何,我不明白为什么jsonArray
is nil
,尽管jsonResponse1
包含我上面写的值。
编辑:我的老板写错了 json 字符串。谢谢大家的建议!:)