2014-02-21 136 views
-1
"RestInfo": [ 
     { 
      "id": "1", 
      "store_id": "3", 
      "staff_id": "1075", 
      "default_rest": "0", 
      "restaurant_name": "Imagine Restaurant", 
      "restaurant_location": "Sydney", 
}, 
{ 
      "id": "3", 
      "store_id": "3", 
      "staff_id": "1085", 
      "default_rest": "0", 
      "restaurant_name": "MealsAustralia", 
      "restaurant_location": "Nsw", 
}, 



NSError *err; 
    NSURLResponse *response; 
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err]; 

NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:responseData options: NSJSONReadingMutableContainers error: &err]; 

NSArray *array=[jsonArray objectForKey:@"RestInfo"]; 

for (int i=0; i<[array count]; i++) { 
    NSLog(@"the restrunt==%@",[[array objectAtIndex:i]objectForKey:@"restaurant_location"]); 

我只能得到一個JSON值,但我需要得到更多的價值,請幫助我,我很新的目標C.相同的JSON對象值

+0

解釋一下你想要什麼......! – Mani

+0

在JSON數組結構中沒有']。 –

回答

1

你會得到字典的數組,你需要從字典中獲取的值:

for (int i=0; i<[array count]; i++) { 
     NSDictionary *dicObj = [array objectAtIndex:i]; 
     NSLog(@"%@", [dicObj objectForKey:@"id"]); 
     NSLog(@"%@", [dicObj objectForKey:@"store_id"]); 
     NSLog(@"%@", [dicObj objectForKey:@"staff_id"]); 
     NSLog(@"%@", [dicObj objectForKey:@"default_rest"]); 
     NSLog(@"%@", [dicObj objectForKey:@"restaurant_name"]); 
     NSLog(@"%@", [dicObj objectForKey:@"restaurant_location"]); 
    } 
+2

夥計們 - 我們已經有Objective C文字近2年了!時間習慣於簡潔表示法:-) http://blog.bignerdranch.com/398-objective-c-literals-part-1/ – cacau

+0

好點+1,謝謝。 – Nilesh

+0

其工作正常,我需要顯示這些值到表視圖 – user3251949

0

試試這個: -

for (int i=0; i<[array count]; i++) 

NSLog(@"the restrunt==%@",[array addObject:[[[jsonArray objectForKey:@"RestInfo"] objectAtIndex:i] objectForKey:@"restaurant_location"]]; 
+0

我還沒有嘗試過,寫在這裏..但我認爲它應該工作。 –

相關問題