"[
{
\"TheatreName\": \"FunCinemas\",
\"TheatreId\": 1,
\"City\": \"Chandigarh\"
},
{
\"TheatreName\": \"PVRElanteMall\",
\"TheatreId\": 2,
\"City\": \"Chandigarh\"
},
{
\"TheatreName\": \"PiccadilySquare\",
\"TheatreId\": 3,
\"City\": \"Chandigarh\"
}
]"
我想解析这些数据,即将所有对象Theatrename,id,city
分开答案 0 :(得分:3)
我尝试使用您的JSON值
创建演示场景以下是代码:
- (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];
}
}