0
{
"id": "1",
"result": [
{
"Name": "John",
"Statu": "Online"
},
{
"Name": "Alex",
"Statu": "Online"
},
{
"Name": "Diaz",
"Statu": "Offline"
}
]
}
我如何提取每一個「車」的JSON對象,並把它變成一個本地對象?我嘗試了幾種方法,但我不能那樣做。如何將Json請求轉換爲本地對象或列表?
NSString *responseString = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
NSString *responseDict = [responseString JSONValue];
NSArray *objects = [NSArray arrayWithObjects:[responseDict valueForKeyPath:@"result.Name"],[responseDict valueForKeyPath:@"result.Statu"],nil];
NSLog(@"objects Array: %@",objects);
**==> NSLOG gives:
(
(
"John",
"Alex",
"Diaz"
),
(
"Online",
"Online",
"Offline"
)
)
NSArray *resultsArray = [responseString JSONValue];
for (NSDictionary *personDict in resultsArray)
{
NSLog(@"ihaleAdi =: %@",[carDict valueForKey:@"result.ihaleAdi"]);
NSLog(@"ihaleDurum =: %@",[carDict valueForKey:@"result.Statu"]);
}
但是我得到一個錯誤我想只是推薦他們但我不能做任何人可以幫助我嗎?感謝您閱讀
頂行(NSString * responseString = [request responseString];)假定您正在使用ASIHttpRequest委託方法。如果您以其他方式實例化請求對象,請忽略該行。 –
第二行創建一個被JSONValue覆蓋的數組。你已經泄露了它。 – Abizern
它給出了一個錯誤,如:[__NSCFDictionary objectAtIndex:]:無法識別的選擇發送到實例0x6b43300 – user1117361