0
我有一個JSON數組得到數組,像這樣:如何從花葯陣列
a= {"title":"workers","data":[{"name":"tom","id":"LBJP01Z"},{"name":"bob","id":"LBJP08Z"},{"name":"bill","id":"LBJP02Z"}]},{"title":"teachers","data":[{"name":"jill","id":"LZJP01Z"},{"name":"tim","id":"LBJP03Z"},{"name":"sam","id":"LBJP07Z"}]}
我想要得到的結果是這樣的:
tom
bob
bill
jill
tim
sam
我的代碼:
for (int i = 0; i < [a count]-1; i++) {
for (int j = 0; j < [a[i] count]-1; j++)
{
NSString *str = [NSString stringWithFormat:@"%@",[[[[a objectAtIndex:i]objectForKey:@"data"]objectAtIndex:j] objectForKey:@"name"]];
NSLog(@"%@",str);
}
}
但最終,我得到如下結果:
tom
tom
tom
tom
tom
tom
轉到json.org所和學習JSON語法。學習只需要5-10分鐘。然後你會更好地理解你在做什麼。 –