使用iOS 5在iPhone中使用JSON数据

使用iOS 5在iPhone中使用JSON数据,iphone,objective-c,ios,Iphone,Objective C,Ios,如何在iOS 5中使用此JSon数据 ({assets = ( { identity = 34DL3611;}, {identity = 34GF0512;}, {identity = 34HH1734;}, {identity = 34HH1736;}, {identity = 34YCJ15;} ); identity = DEMO;}) 通过此调用在控制台上获取此数据 id list =[NSJSONSerialization JSONObjectWithData:data o

如何在iOS 5中使用此JSon数据

({assets = ( { identity = 34DL3611;}, {identity = 34GF0512;}, {identity = 34HH1734;}, {identity = 34HH1736;}, {identity = 34YCJ15;} );

identity = DEMO;})
通过此调用在控制台上获取此数据

    id list =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];

NSLog(@"VLIST: %@", list);
现在,在使用encoding:NSUTF8StringEncoding之后,我已经获得了完全JSON格式的数据,我想使用iOS 5的原生jsonserializer

NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
JSON数据是:

[{"assets":[{"identity":"34DL3611"},{"identity":"34GF0512"},{"identity":"34HH1734"},{"identity":"34HH1736"},{"identity":"34YCJ15"}],"identity":"DEMO"}]
现在,我如何获取这些数据,以便获取资产数组值并将它们填充到表中,然后获取identity的值(即DEMO)以将其用作头

thanx具有更好的性能,非常容易添加到项目中(2个文件),并且易于使用

NSDictionary *dict = [myJsonString objectFromJSONString];
当我处理json数据时,我总是通过。这让我知道json是有效的,并提高了我对数据的理解

具有更好的性能,非常容易添加到项目中(2个文件),并且易于使用

NSDictionary *dict = [myJsonString objectFromJSONString];
当我处理json数据时,我总是通过。这让我知道json是有效的,并提高了我对数据的理解

< P>是另一个考虑的选项。

SBJsonParser* parser = [[SBJsonParser alloc] init];
NSDictionary* dict = [parser objectFromString:jsonString];
[parser release];

它非常方便和格式化,非常类似于Apple的类引用。

是另一个要考虑的选项。

SBJsonParser* parser = [[SBJsonParser alloc] init];
NSDictionary* dict = [parser objectFromString:jsonString];
[parser release];

它非常方便,格式非常像Apple的类引用。

您似乎能够成功解析JSON数据,现在想知道如何访问数据。解析的JSON数据是一个
NSDictionary
或一个
NSArray
实例,其中包含
NSDictionary
NSArray
NSString
NSNumber
等实例

从示例数据来看,您的数据似乎嵌套得很重。(目的不太清楚。)它是一个包含字典的数组,包含一个包含字典的数组

您可以这样访问它:

NSArray list =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
NSDictionary dict = [list objectAtIndex: 0];
NSArray assets = [dict objectForKey: @"assets"];
NSString identity = [dict objectForKey: @"identity"];
for (NSUInteger index = 0; index < [assets count]; index++) {
    NSDictionary itemDict = [assets objectAtIndex: index];
    NSString itemIdentity = [itemDict objectForKey: @"identity"];
}
NSArray list=[NSJSONSerialization JSONObjectWithData:data选项:NSJSONReadingAllowFragments错误:&error];
NSDictionary dict=[list objectAtIndex:0];
NSArray资产=[dict objectForKey:@“资产”];
NSString标识=[dict objectForKey:@“标识”];
对于(整数索引=0;索引<[资产计数];索引++){
NSDictionary itemDict=[assets objectAtIndex:index];
NSString itemIdentity=[itemDict objectForKey:@“identity”];
}

您似乎能够成功解析JSON数据,现在想知道如何访问数据。解析的JSON数据是一个
NSDictionary
或一个
NSArray
实例,其中包含
NSDictionary
NSArray
NSString
NSNumber
等实例

从示例数据来看,您的数据似乎嵌套得很重。(目的不太清楚。)它是一个包含字典的数组,包含一个包含字典的数组

您可以这样访问它:

NSArray list =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
NSDictionary dict = [list objectAtIndex: 0];
NSArray assets = [dict objectForKey: @"assets"];
NSString identity = [dict objectForKey: @"identity"];
for (NSUInteger index = 0; index < [assets count]; index++) {
    NSDictionary itemDict = [assets objectAtIndex: index];
    NSString itemIdentity = [itemDict objectForKey: @"identity"];
}
NSArray list=[NSJSONSerialization JSONObjectWithData:data选项:NSJSONReadingAllowFragments错误:&error];
NSDictionary dict=[list objectAtIndex:0];
NSArray资产=[dict objectForKey:@“资产”];
NSString标识=[dict objectForKey:@“标识”];
对于(整数索引=0;索引<[资产计数];索引++){
NSDictionary itemDict=[assets objectAtIndex:index];
NSString itemIdentity=[itemDict objectForKey:@“identity”];
}

不管这是什么,都不是JSON。我想您必须编写自己的解析器。似乎调用mei的
[NSDictionary description]
的输出已经添加了代码,我正是通过这些代码获得此结果的data@OmerKhan:如果这是
[NSDictionary description]的输出
:这是数据传输的格式,还是只是说明数据结构的示例?您想从文件或web服务读取数据吗?我在问题中添加了确切的JSON数据,请指导我,不管这是什么,它不是JSON。我想您必须编写自己的解析器。似乎调用mei的
[NSDictionary description]
的输出已经添加了代码,我正是通过这些代码获得此结果的data@OmerKhan:如果这是
[NSDictionary description]的输出
:这是数据传输的格式,还是只是说明数据结构的示例?您想从文件或web服务读取数据吗?我已在问题中添加了确切的JSON数据请指导mecodo请查看我已更正的问题。。。现在请导游me@OmerKhan:感谢您添加JSON数据。它确认我正确理解了接收数据的结构。所以我的答案是正确的。科多,请看我已经更正的问题。。。现在请导游me@OmerKhan:感谢您添加JSON数据。它确认我正确理解了接收数据的结构。所以我的答案是正确的。