JSON解析

demo
1.json转字典

    NSString *jsonPath = [[NSBundle mainBundle] pathForResource:@"Books" ofType:@"geojson"];
    NSData *data = [NSData dataWithContentsOfFile:jsonPath];
    NSArray *pathResult = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    NSLog(@"%@",pathResult);

2.字典转json

    NSData *data1 = [NSJSONSerialization dataWithJSONObject:pathResult options:0 error:nil];
    NSString *json = [[NSString alloc] initWithData:data1 encoding:NSUTF8StringEncoding];
    NSLog(@"%@",json);

你可能感兴趣的:(JSON解析)