【发布时间】:2013-08-02 13:17:09
【问题描述】:
我在从 Json 响应中获取数据时遇到问题。
这是一个示例数据结构:
(
{
AT = "<null>";
DId = 0;
DO = 0;
PLId = 33997;
PdCatList = (
{
PLId = 33997;
PPCId = 0;
pdList = (
{
IsDis = 0;
IsPS = 0;
IsT = 1;
PA = 1;
PCId = 119777;
}
);
}
);
PdId = 0;
SId = 0;
Sec = 1;
},
{
AT = "<null>";
DId = 0;
DO = 11;
Dis = 0;
PLId = 34006;
PdCatList = (
{
PLId = 34006;
PPCId = 0;
pdList = (
{
IsDis = 0;
IsPS = 0;
IsT = 1;
PA = 1;
PCId = 119830;
},
{
IsDis = 0;
IsPS = 0;
IsT = 1;
PA = 1;
PCId = 119777;
}
);
},
{
PLId = 33997;
PPCId = 0;
pdList = (
{
IsDis = 0;
IsPS = 0;
IsT = 1;
PA = 1;
PCId = 119777;
}
);
}
);
PdId = 0;
SId = 0;
Sec = 1;
},
)
我将如何解析结果结构? 我想直接获取值列表。如果我在元组中有多个值,例如执行者 PdCatList、pdList。我将如何访问这些值? 谁能帮帮我
谢谢
我的代码是
NSError *error;
Array1 = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
for(int i=0;i<[Array1 count];i++)
{
NSDictionary *dict1 = [Array1 objectAtIndex:i];
NSLog(@"Array1.....%@",dict1);
Array2=[dict1 valueForKey:@"PdCatList"];
for(int i=0;i<[Array2 count];i++)
{
NSDictionary *dict2 = [Array2 objectAtIndex:i];
NSLog(@"Array2.....%@",dict2);
Array3=[dict2 valueForKey:@"pdList"];
for(int i=0;i<[Array3 count];i++)
{
NSDictionary *dict3 = [Array3 objectAtIndex:i];
NSLog(@"Array3.....%@",dict3);
}
}
}
【问题讨论】:
-
我看到了你的问题,发现你总是为每一个新的
JSON回复提出一个新问题。 -
for(int i=0;i
-
看看答案:stackoverflow.com/a/17025824/1603072。它可以帮助您了解 JSON 解析是什么。
标签: iphone ios objective-c json ios5