2013-06-30 29 views
0

是这样的内容...解析JSON把所有的内容在一个NSArray中

[ 
    { 
     "id": "", 
     "title": "", 
     "website": "", 
     "categories": [ 
      { 
       "id": "", 
       "label": "" 
      } 
     ], 
     "updated": 
    }, 
    { 
     "id": "", 
     "title": "", 
     "website": "", 
     "categories": [ 
      { 
       "id": "", 
       "label": "" 
      } 
     ], 
     "updated": 
    } 
] 

我怎样才能插入一个阵列中每一个的供应源?

NSDictionary *results = [string JSONValue]; 
NSArray *subs = [results valueForKey:@"KEY"]; 

我必须插入哪个键? 感谢

+1

你有一个字典数组。您必须以某种方式迭代数组以从字典中提取值。它非常简单,只需查看结构并了解代码必须与结构匹配。花5分钟时间在json.org上学习JSON语法,以便理解它。 –

+0

当然,您已经编辑了上述JSON,使其不再有效。 –

回答

2

,因为我可以看到你的结构,你会摆脱这种的JSON字符串

NSArray: 
[ 
    NSDictionary: 
    { 
     NSString: "id", 
     NSString: "title", 
     NSString: "website", 
     NSArray: "categories": 
     [ 
      NSDictionary: 
      { 
       NSString: "id", 
       NSString: "label" 
      } 
     ], 
     NSNumber: "updated" 
    }, 
    NSDictionary: 
    { 
     ... 
    } 
] 

所以,你已经数组“订阅”的根,你必须与他们的索引itterate他们在数组中。对于第一个ID,即[[myJsonStructure objectAtIndex:0] objectForKey:@"id"];

+0

非常感谢你! –

+0

对于较新的编译器版本,还应该提及新的语法:* myJsonStructure [0] [@“id”]; *。 –