提问人:daleijn 提问时间:3/3/2014 最后编辑:Darshan Kunjadiyadaleijn 更新时间:3/3/2014 访问量:77
NSDictionary 中的嵌套级别
Nesting level in NSDictionary
问:
我从网络获取数据,然后创建 NSDictionary。这是我的 NSDictionary 的一部分:
Car = (
{
Number = 10;
Places = {
text = "001,003,004,022,023,024,026,027,029,030,031,033,035,036,038,040,042,043,044,047,048,049,050,051,052";
};
Seats = {
SeatsDn = 8;
SeatsLateralDn = 4;
SeatsLateralUp = 7;
SeatsUp = 6;
};
},
{
Number = 11;
Places = {
text = "006,008,014,016,018,020,022,026,028,033,034,035,036,038,040,042,043,044,045,046,049,050,052";
};
Seats = {
SeatsDn = 2;
SeatsLateralDn = 3;
SeatsLateralUp = 7;
SeatsUp = 11;
};
}
);
ClassService = {
Type = "1_type";
text = "First type descr";
};
Owner = {
Country = {
Code = 27;
Name = "Country name";
};
Type = "\U041a\U0417\U0425/\U041a\U0417\U0425";
};
Tariff = {
text = 1122;
};
TariffService = {
text = 250;
};
TrainLetter = "\U0425";
Type = "\U041f\U043b\U0430\U0446\U043a\U0430\U0440\U0442\U043d\U044b\U0439";
}
);
问题是有 2 个对象,它们有自己的 Number、Places、Seats,但在 ClassService 下,它们都有一对二。我怎么知道数字为 10 的对象有
ClassService =
Type = "1_type";
text = "First type descr"
和
Tariff = {
text = 1122;
数字为 11 的对象有
ClassService =
Type = "1_type";
text = "First type descr"
和
Tariff = {
text = 1122;
现在我正在使用这个:
NSarray *CarsNumbers = [[myDict valueForKey: @"Car"] valueForKey: @"Number"];`
NSarray *CarsTariffs = [[[myDict valueForKey: @"Car"] valueForKey: @"Tariff"] valueForKey: @"text"];
This way I see that `CarsNumbers.count = 2, `CarsTariffs.count = 1`
.我怎样才能做对?
答:
0赞
Vijay-Apple-Dev.blogspot.com
3/3/2014
#1
数字 10 和数字 11 对象位于相同的 ClassService 和 Quotay 中,这就是为什么它像这样包含在数组中的原因 ()。
你可以只使用
[myDict valueForKey:@"ClassService"]valueForKey:@"Type"]]// Type = "1_type";
[myDict valueForKey:@"Tariff"]valueForKey:@"text"]]// text = 1122;
NSArray *Cars = [myDict valueForKey:@"Car"];
for (NSDictionary *aCar in Cars) {
if ([aCar valueForKey:@"Number"] == 10) {
//your Car NSObject.ClassService = [myDict valueForKey:@"ClassService"]valueForKey:@"Type"]]
}
}
评论
0赞
daleijn
3/3/2014
10 - 举个例子,我不知道它会是什么数字
上一个:XML - 转义字符串的正确方法
评论