gpt4 book ai didi

ios - 具有多个循环的 Json 解析

转载 作者:行者123 更新时间:2023-11-29 13:17:01 26 4
gpt4 key购买 nike

如何在 objective-c 中循环遍历 json [{first set of values},{data->children->data->body} 的这一部分?

Json是

  [
{
"kind": "Listing"
},
{
"kind": "Listing",
"data": {
"children": [
{
"data": {
"body": "body1"
}
},

{
"data": {
"body": "body2"
}
}
]
}
}
]

我当前的代码是

m_ArrList=[[NSMutableArray alloc]init];
NSDictionary *infomation = [self dictionaryWithContentsOfJSONString:@"surveyquestion.json"];
NSArray *array=[infomation objectForKey:@"data"];
int ndx;
NSLog(@"%@",array);
for (ndx = 0; ndx < [array count]; ndx++) {
NSDictionary *stream = (NSDictionary *)[array objectAtIndex:ndx];

NSArray *string=[stream valueForKey:@"children"];

//i am stuck here
}

我在“//我被困在这里”时该怎么办?

最佳答案

您可能需要将 @"children" 字典的值添加到数组中,然后解析该数组以获取 children 中的数据

[childrenArray addObject:[stream objectForKey:@"children"]];

// finally parse childrenArray

关于ios - 具有多个循环的 Json 解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15496963/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com