2016-06-08 42 views
1

Wie dieses JSON-Array zu lösen, ich versuche zu oft, aber nicht "Business_Details" Array abrufen. Ich hole nur zuerst "business_category_name" dann "business_details" -Array nicht holen. Ich denke nicht erklären, bitte versuchen Sie zu verstehen und bitte helfen Sie mir. Ich bin sehr müdeWie löst man das json-Wörterbuch?

Json

"status": [ 
{ 
    "business_category_name": "Banks\/Credit Unions\/Landers", 
    "business_details": [ 
    { 
     "img_url": "http:\/\/edutimeapp.com\/toshow\/chamber-of-commerc\/member-logo\/1464667619-pnc.jpg", 
     "name": "PNC Bank", 
     "des": "PNC offers a wide range of services for all our customers, from individuals and small businesses, to corporations and government entities", 
     "address": "", 
     "email": "[email protected]", 
     "phone": "260-422-5922", 
     "member_since": "2016-05-31", 
     "img_company": "http:\/\/edutimeapp.com\/toshow\/chamber-of-commerc\/member-logo\/1464667619-pnc.jpg", 
     "website": "", 
     "city": "Fort Wayne", 
     "state": "IN", 
     "zip": "46808" 
    } 
    ] 
}, 
{ 
    "business_category_name": "Cleaning Services", 
    "business_details": [ 
    { 
     "img_url": "http:\/\/edutimeapp.com\/toshow\/chamber-of-commerc\/uploads\/logo250.png", 
     "name": "tsst company", 
     "des": "rudurgg ", 
     "address": "2005 s calhoun ", 
     "email": "", 
     "phone": "2602496687", 
     "member_since": "2016-05-31", 
     "img_company": "http:\/\/edutimeapp.com\/toshow\/chamber-of-commerc\/uploads\/logo250.png", 
     "website": "", 
     "city": "fort wayne", 
     "state": "in", 
     "zip": "46825" 
    } 
    ] 
}, 

Verwenden Json Daten

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 

{ 

NSError *error; 


NSLog(@"Error in receiving data %@",error); 

NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error]; 

NSLog(@"response data %@",json); 


NSArray *results = [json objectForKey:@"status"]; 

namearray= [results valueForKey:@"business_category_name"]; 

emailarray = [results valueForKey:@"email"]; 

[self.tableview reloadData]; 

} 

Antwort

3

ViewController.m

@interface ViewController() 
{ 
    NSArray * yourArray; 
} 


NSLog(@"response data %@",json); 
NSArray *results = [json objectForKey:@"status"];  
yourArray = [[[results objectAtIndex:0] valueForKey:@"business_details"] objectAtIndex:0]; 

Dies wird Ihnen Ausgabe von "business_details" für 0 geben Index (erstes Objekt)

Ausgang:

[ 
    { 
     "img_url": "http:\/\/edutimeapp.com\/toshow\/chamber-of-commerc\/member-logo\/1464667619-pnc.jpg", 
     "name": "PNC Bank", 
     "des": "PNC offers a wide range of services for all our customers, from individuals and small businesses, to corporations and government entities", 
     "address": "", 
     "email": "[email protected]", 
     "phone": "260-422-5922", 
     "member_since": "2016-05-31", 
     "img_company": "http:\/\/edutimeapp.com\/toshow\/chamber-of-commerc\/member-logo\/1464667619-pnc.jpg", 
     "website": "", 
     "city": "Fort Wayne", 
     "state": "IN", 
     "zip": "46808" 
    } 
] 

Wenn Sie wollen, es zu benutzen in Ihrem tableview dann müssen Sie indexPath.row anstelle des Index, wie unten zu schreiben.

yourArray = [[[results objectAtIndex:indexPath.row] valueForKey:@"business_details"] objectAtIndex:0]; 
+0

Dank für die Antwort, habe ich Tableview indexPath .row ist gleich wie, aber führt zu einem nicht deklarierten Array-Fehler. wie zu verwenden, bitte erklären Sie –

+0

Verwenden Sie Ihr Array anstelle von Array ... – Gati

+0

gleichen Fehler zeigen, wie zu implementieren –

0

Wenn die komplette Ausgabe ein Wörterbuch von json bezeichnet ist, können Sie das tun:

NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:response 
                  options:NSJSONReadingMutableLeaves 
                   error:&error]; 
NSArray *status = json[@"status"]; 
NSDictionary *firstStatus = status[0]; 
NSArray *businessDatails = firstStatus[@"business_details"] 
// Likely you want to continue 
NSDictionary *firstBusinessDetail = businessDetails[0]; 
NSMutableString *name = firstBusinessDetail[@"name"]M 

oder setzen sie alle zusammen:

NSMutableArray *businessDatails = json[@"status"][0][@"business_details"]; 
+0

* UITableViewCell Indizierung in einem nicht laden * Was bedeutet das? –

+0

* Einfaches Label auf einer Druckzeichenfolge, aber TableView Cell-Label in einer nicht druckbaren Namenszeichenfolge. * Und das? –

+0

??? Ordne es dem Label zu !? –

Verwandte Themen