本文介绍了如何从Objective -C中的Json响应中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在从Json响应中获取数据时遇到问题。
I have a problem with fetching data from Json response.
以下是一个示例数据结构:
Here is an example data structure :
(
{
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;
},
)
我将如何解析生成的结构?
我想直接得到一个值列表。如果我在tupel中有多个值,例如执行者PdCatList,pdList,该怎么办?我将如何访问这些值?
任何人都可以帮助我
how would i parse the resulting Structure ?I would like to get a list of values directly. What if i have several values in a tupel for example performer PdCatList, pdList. How would i access those values?Can anyone help me
谢谢
我的代码是
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);
}
}
}
推荐答案
试试这个......
Try this...
NSError *error;
Array1 = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
for(int i=0;i<[Array1 count];i++)
{
NSDictionary *dict1 = [Array1 objectAtIndex:i];
ATArray =[dict1 valueForKey:@"AT"];
DIdArray =[dict1 valueForKey:@"DId"];
DOArray =[dict1 valueForKey:@"DO"];
PLIdArray =[dict1 valueForKey:@"PLId"];
etc...
Array2=[dict1 valueForKey:@"PdCatList"];
for(int i=0;i<[Array2 count];i++)
{
NSDictionary *dict2 = [Array2 objectAtIndex:i];
PLIdArray =[dict2 valueForKey:@"PLId"];
PPCIdArray =[dict2 valueForKey:@"PPCId"];
etc…
Array3=[dict2 valueForKey:@"pdList"];
for(int i=0;i<[Array3 count];i++)
{
NSDictionary *dict3 = [Array3 objectAtIndex:i];
IsDisArray =[dict3 valueForKey:@"IsDis"];
IsPSArray =[dict3 valueForKey:@"IsPS"];
IsTArray =[dict3 valueForKey:@"IsT"];
PAArray =[dict3 valueForKey:@"PA"];
PCIdArray =[dict3 valueForKey:@"PCId"];
}
}
}
这篇关于如何从Objective -C中的Json响应中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!