我一直在想幾天來弄清楚如何解析這個JSON到一個分段的UITable,但我不成功,我只能弄清楚如何獲得節名稱,但未能獲取每個部分中每一行的行數和數據。分段的UITable&JSON
由於交通團隊可能會不時變化,他們的名字可能會改變,所以我想我需要使用allKeys來找出每節的標題1st。
請幫助並指出我正確的方向來提取分區UITable的數據,謝謝。
{
"transport" : {
"public" : [
{
"transport_id" : "2",
"transport_name" : "Ferry"
},
{
"transport_id" : "3",
"transport_name" : "Bus"
},
{
"transport_id" : "4",
"transport_name" : "Taxi"
},
{
"transport_id" : "5",
"transport_name" : "Tram"
}
],
"Private" : [
{
"transport_id" : "11",
"transport_name" : "Bicycle"
},
{
"transport_id" : "12",
"transport_name" : "Private Car"
}
],
"Misc" : [
{
"transport_id" : "6",
"transport_name" : "By Foot"
},
{
"transport_id" : "7",
"transport_name" : "Helicopter"
},
{
"transport_id" : "8",
"transport_name" : "Yatch"
}
]
}
}
NSDictionary *results = [jsonString JSONValue];
NSDictionary *all = [results objectForKey:@"transport"];
NSArray *allKeys = [all allKeys];
NSArray *transports = [results objectForKey:@"transport"];
for (NSDictionary *transport in transports)
{
[transportSectionTitle addObject:(transport)];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [transportSectionTitle count];
}
你想說,運輸,公私錯過這些改變或在其內部的數據在一段時間內發生變化。 – 2012-01-27 08:33:39