[
{
"Id": 52,
"Name": "name1",
"author": "john"
},
{
"Id": 53,
"Name": "name2",
"author": "jacob"
},
{
"Id": 54,
"Name": "name3",
"author": "jobin"
}
]
我用下面的代碼來獲取並沒有主鍵無法擷取的JSON值在IOS沒有鑰匙
SBJsonParser *parser1 = [[SBJsonParser alloc] init];
NSURLRequest *request1 = [NSURLRequest requestWithURL:[NSURL URLWithString:str2]];
// Perform request and get JSON back as a NSData object
NSData *response1 = [NSURLConnection sendSynchronousRequest:request1 returningResponse:nil error:nil];
NSError *error;
NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:response1 options:kNilOptions error:&error];
解析此JSON數組,但我得到了以下異常
data parameter is nil
這個異常是發生在這段代碼
NSData *response1 = [NSURLConnection sendSynchronousRequest:request1 returningResponse:nil error:nil];
如何迭代id值?
檢查您是否在NSError變量中發現任何錯誤... –
您是否在'jsonArray'中獲得響應? –
有沒有必要'主鍵'來訪問元素?您可以輕鬆訪問元素。 –