2016-09-20 10 views
-1
"[ 
    { 
    \"TheatreName\": \"FunCinemas\", 
    \"TheatreId\": 1, 
    \"City\": \"Chandigarh\" 
    }, 
    { 
    \"TheatreName\": \"PVRElanteMall\", 
    \"TheatreId\": 2, 
    \"City\": \"Chandigarh\" 
    }, 
    { 
    \"TheatreName\": \"PiccadilySquare\", 
    \"TheatreId\": 3, 
    \"City\": \"Chandigarh\" 
    } 
]" 

ich diese Daten analysieren wollen, das heißt getrennt werden alle Objekte Theatrename, id, StadtParse JSON-Antwort-String in Objective - C

Antwort

2

Ich habe versucht, eine Demo-Szenario mit Ihrem JSON Wert zu schaffen

Hier

ist der Code:

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    NSString *str = @"[{\"TheatreName\": \"FunCinemas\",\"TheatreId\": 1,\"City\":\"Chandigarh\"},{\"TheatreName\":\"PVRElanteMall\",\"TheatreId\": 2,\"City\": \"Chandigarh\"},{\"TheatreName\": \"PiccadilySquare\",\"TheatreId\": 3,\"City\": \"Chandigarh\"}]"; 
    NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding]; 

    NSError *err = nil; 
    NSArray *jsonData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&err]; 

    NSMutableArray *arrResult = [NSMutableArray array]; 

    for (NSDictionary *dict in jsonData) { 

     NSLog(@"TheatreName %@", dict[@"TheatreName"]); 
     NSLog(@"TheatreId %@", dict[@"TheatreId"]); 
     NSLog(@"City %@", dict[@"City"]); 

     [arrResult addObject:dict]; 
    } 

} 
+0

Thanku ... es hat funktioniert –

+0

Dann akzeptieren und abstimmen, die Antwort, so dass andere mit Blick auf gleiches Problem wissen kann. – Janmenjaya