我有一个看起来那样的字典:
{
"from": 0,
"to": 1412045889232,
"series": [
{
"component": "Table",
"points": [
{
"ts": "1409745374148", //time stamps
"value": "34"
},
{
"ts": "1409745564148",
"value": "36"
}
]
}
{
"component": "Table2",
"points": [
{
"ts": "1409745374148", //time stamps
"value": "43"
},
{
"ts": "1409745564148",
"value": "39"
}
]
}
]
}
我可以轻松地从中获取。 该系列还:
NSLog(@"/n Fetched component = %@", [[dict objectForKey:@"series"] valueForKey:@"component"] );
NSLog(@"/n Fetched points = %@", [[dict objectForKey:@"series"] valueForKey:@"points"] );
我想要的是获得定义ts的值 任何想法?
答案 0 :(得分:2)
NSDictionary *jsonDictionary ; // Contains Json Serialized Data
NSArray *seriesArray = [jsonDictionary valueForKey:@"series"];
for (NSDictionary *innerDictionary in seriesArray)
{
NSLog(@"%@" ,[innerDictionary valueForKey:@"component"]);
for (NSDictionary *pointsDict in [innerDictionary valueForKey:@"points"])
{
NSLog(@"%@" , [pointsDict valueForKey:@"ts"]);
}
}