Iphone 帮助我从json提要中获取每个元素?请
我有以下JSON数据:Iphone 帮助我从json提要中获取每个元素?请,iphone,ios,Iphone,Ios,我有以下JSON数据: { "data":{ "mat_149":{ "id":"149", "title":"The closing of 40% profit within 9 month", "teaser":"profit within 9 months only which is equal to 52% annual profit", "body":" The a
{
"data":{
"mat_149":{
"id":"149",
"title":"The closing of 40% profit within 9 month",
"teaser":"profit within 9 months only which is equal to 52% annual profit",
"body":" The auction was presented in a very high and commercial lands.\u000d\u000a",
"files":{
"911":{
"fid":"911",
"filename":"22.JPG",
"filepath":"http://mysite/files/22_0.JPG"
}
}
},
"mat_147":{
"id":"147",
"title":"Company launches the city ",
"teaser":"demands for distinguished lands.",
"body":" The area size is quare meters This is evident through projects and many other projects.\u000d\u000a\u000d\u000a",
"files":{
"906":{
"fid":"906",
"filename":"2D7z.jpg",
"filepath":"http://mysite/dlr/files/2D7Z.jpg"
}
}
},
"mat_link":"mysite.com/"
}
}
我使用json框架对其进行如下解析:
NSString *response = [[NSString alloc] initWithData:receivedData encoding:NSASCIIStringEncoding] ;
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *data = (NSDictionary *) [parser objectWithString:response error:nil];
NSLog(@"Data : %@", [data valueForKey:@"data"] );
我得到数据:
NSLog(@"Data : %@", [data objectForKey:@"data"] );
我正在获取数据,但我应该如何获取“文件”项,如“fid”、“文件名”、“文件路径”。如何从“数据”n“文件”中获取每个元素并将其存储到某些NSString中
有人能指出我要做什么吗?请它们都是子字典,不是吗, 只需尝试记录整个词典,就可以:
NSLog(@"%@", data);
然后你可以看到它的结构
要获取所有其他数据,需要创建一个数据模型来保存所有数据,该模型知道调用哪些键来获取特定字符串
或者你可以调用[数据所有键];
通过迭代,获取您拥有模型对象的字典
例如:
//你在什么地方申报这个
NSArray *keys = [data allKeys]
for (NSString *key in [data allKeys]) {
NSDictionary *oneObject = [dictionary objectForKey:key];
MyObjectModel *object = [[MyObjectModel alloc] init];
object.id = [oneObject objectForKey:@"id"];
object.title = [oneObject objectForKey:@"title"];
//etc
//then you create another dict for files
}
亚历克斯