美文网首页
JSON解析

JSON解析

作者: 精神薇 | 来源:发表于2016-12-22 20:35 被阅读0次

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解析

      本文链接:https://www.haomeiwen.com/subject/zkuhvttx.html