如何获取或访问nsdictionary中的值,我只想从冷却器中获取valuetext
data (
(
{
Caption = Chiller;
MetricClass = 10;
Value = "109.4000015258789";
ValueText = "109.4";
},
{
Caption = "Chiller Product";
MetricClass = 10;
Value = "37.40000152587891";
ValueText = "37.4";
},
{
Caption = Freezer;
MetricClass = 10;
Value = 104;
ValueText = "104.0";
},
{
Caption = "Freezer Product";
MetricClass = 10;
Value = "42.79999923706055";
ValueText = "42.8";
}
),
(
{
Caption = Chiller;
MetricClass = 10;
Value = "109.4000015258789";
ValueText = "109.4";
},
{
Caption = "Chiller Product";
MetricClass = 10;
Value = "48.20000076293945";
ValueText = "48.2";
},
{
Caption = Freezer;
MetricClass = 10;
Value = 104;
ValueText = "104.0";
},
{
Caption = "Freezer Product";
MetricClass = 10;
Value = "53.59999847412109";
ValueText = "53.6";
}
),
答案 0 :(得分:0)
这看起来不像有效(JSON)数据......但如果它只是NSDiction的NSArray,那么这应该有效:
for (NSDictionary *dict in data)
{
NSLog(@"%@", dict[@"Caption"]);
}
答案 1 :(得分:0)
你所拥有的NSArray包含NSArrays,其中包含NSDictionaries。 (在NSLog转储中,数组被()
括起来,而字典被{}
括起来。)
你需要“剥洋葱” - 使用objectAtIndex
再次访问数组条目objectAtIndex
以访问内部数组的条目,然后使用objectForKey
从中获取值字典。
答案 2 :(得分:0)
由于@Hot声明你有一个字典数组数组,并且可以轻松使用新的文字语法。
示例:
test: NSArray * data = @[
@[
@{
@"Caption" : @"Chiller",
@"MetricClass" : @10,
@"Value" : @"109.4000015258789",
@"ValueText" : @"109.4",
},
@{
@"Caption" : @"Chiller Product",
@"MetricClass" : @10,
@"Value" : @"37.40000152587891",
@"ValueText" : @"37.4",
},
@{
@"Caption" : @"Freezer",
@"MetricClass" : @10,
@"Value" : @104,
@"ValueText" : @"104.0",
},
@{
@"Caption" : @"Freezer Product",
@"MetricClass" : @10,
@"Value" : @"42.79999923706055",
@"ValueText" : @"42.8",
}
],
@[
@{
@"Caption" : @"Chiller",
@"MetricClass" : @10,
@"Value" : @"109.4000015258789",
@"ValueText" : @"109.4",
},
@{
@"Caption" : @"Chiller Product",
@"MetricClass" : @10,
@"Value" : @"48.20000076293945",
@"ValueText" : @"48.2",
},
@{
@"Caption" : @"Freezer",
@"MetricClass" : @10,
@"Value" : @104,
@"ValueText" : @"104.0",
},
@{
@"Caption" : @"Freezer Product",
@"MetricClass" : @10,
@"Value" : @"53.59999847412109",
@"ValueText" : @"53.6",
}
]
];
NSLog(@"Value: %@", data[0][0][@"Value"]);
NSLog(@"Value: %@", [[[data objectAtIndex:0]objectAtIndex:0]objectForKey:@"Value"]);
价值:109.4000015258789
价值:109.4000015258789
答案 3 :(得分:0)
谢谢大家的时间和回复,从回答中我发现了我需要做的事情。
for (NSArray *test in [dictobject valueForKey:@"ValueText"]) {
[arrayobject addObject:[test objectAtIndex:2]];
}
再次感谢。