Ale*_*der 2 iphone parsing json ios
所以我已经在我的项目上运行了json-framework,但需要帮助搞清楚如何使用它来解析这个json字符串:
[
{
"id":"0",
"name":"name",
"info":"This is info",
"tags":
[
{
"id":"36",
"tag":"test tag"
},
{
"id":"37",
"tag":" tag 2"
}
],
"other":"nil"
},
{
"id":"1",
"name":"name",
"info":"This is info",
"tags":
[
{
"id":"36",
"tag":"test tag"
},
{
"id":"37",
"tag":" tag 2"
}
],
"other":"nil"
}
Run Code Online (Sandbox Code Playgroud)
]
关于如何使用这种特定类型的json的任何帮助和示例代码都会很棒.不知怎的,我无法把它写进一本我能读出来的字典里.非常感谢.
您无法将此字符串输入字典的原因是因为它不是字典,而是字典数组
您可以通过将值存储在NSArray中将值获取到Objective-C对象中:
NSArray *objects = (NSArray*) [jsonString JSONValue];
Run Code Online (Sandbox Code Playgroud)
然后,您可以遍历数组中的那些对象:
for(NSDictionary *dict in objects) {
NSString *id = (NSString *) [dict objectForKey:@"id"];
NSString *name = (NSString *) [dict objectForKey:@"name"];
NSArray *tags = (NSArray *) [dict objectForKey: @"tags"];
//loop over tags here...
for(NSDictionary *tag in tags) {
NSString *tag_id = (NSString *) [tag objectForKey:@"id"];
NSString *tag_name = (NSString *) [tag objectForKey:@"tag"];
}
//...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
282 次 |
| 最近记录: |