【发布时间】:2012-07-20 12:31:11
【问题描述】:
我的 json 文件是这样的
[{"id":"1","category":"New Category1","title":"New Product2","description":"Please type a description1","imgurl":"http:\/\/s.wordpress.org\/about\/images\/wordpress-logo-notext-bg.png","spectitle":"Specification","specvalue":"Value"},{"id":"2","category":"Mobile","title":"Samsung","description":"Please type a description","imgurl":"http:\/\/s.wordpress.org\/about\/images\/wordpress-logo-notext-bg.png","spectitle":"Price","specvalue":"100$"}]
我有 4 个标签,必须在各个标签中打印 id、类别、标题、描述。我已经成功解析了整个 json 对象并打印在一个标签中。我需要显示所有具有相应类别的 json 对象以对应标签。
NSString *labelstring =[NSString stringWithFormat:@"%@",[json objectAtIndex:0]];
label1.text=[NSString stringwithformat: objectForKey:@"id"];
label2.text=[NSString stringwithformat:objectForKey:@"category"];
label3.text=[NSString stringwithformat:objectForKey:@"title"];
label4.text=[NSString stringwithformat:objectForKey:@"description"];
这里的 json 是 NSArray 的一个变量,具有 URL 信息和那些东西...但是如果我尝试获取单个值我无法得到它..请指导...
【问题讨论】:
-
如何分配
json变量?你使用json解析器吗?哪一个? -
那些 stringWithFormat: 调用是多余的......你不知道吗?
标签: objective-c ios xcode json uilabel