2014-10-01 42 views
-1

获得价值JSON我有一个字典谁看起来像:从NSDictionary的

{ 
    "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

的可能重复:http://stackoverflow.com/questions/5547311/how-do-i-parse-json-with-objective-c – 2014-10-01 03:38:49

+0

的dictionnary实际上不是在所有类似我是做试图得到它,但它不是像1 {...} 2 {...}但像“组件”:“表”, “点”:[...} – Nico 2014-10-01 03:56:19

回答

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"]); 
     } 

    } 
+0

谢谢,帮助了很多循环和内部字典。 – Nico 2014-10-01 04:04:34