我应该如何从 json 字符串中读取数据?苹果手机 [英] How should I read the data from a json string? iphone
问题描述
我有一个 NSString "[{"van" : 1,312, "vuan":12,123}]
并且为了获得每个键的这个值,我这样做:
I have in a NSString "[{"van" : 1,312, "vuan":12,123}]
and in order to get this values for every key, I am doing this:
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;
}
可能是我不必使用数组,而是直接在 NSDictionary
中转换 NSData
.
May be I don't have to use an array and instead to convert the NSData
directly in a NSDictionary
.
无论如何,我不明白为什么 jsonArray
是 nil
,尽管 jsonResponse1
包含我上面写的值.
Anyway, I don't understand why jsonArray
is nil
, although jsonResponse1
contains the values I have written above.
我的老板把 json 字符串写错了.谢谢大家的建议!:)
My boss have written the json string wrong. Thank you all for your suggestions!:)
推荐答案
您的 JSON 无效.修理它.这个网站是你的朋友.
Your JSON is invalid. Fix it. This site is your friend.
这篇关于我应该如何从 json 字符串中读取数据?苹果手机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!