#pragma mark - #pragma mark 解析JSON //解析JSON -(void)parserJson { NSString * path = [[NSBundle mainBundle] pathForResource:@"Student" ofType:@"json"]; //从某个路径里面获取内容 NSData * data = [NSData dataWithContentsOfFile:path]; NSError * error = nil; NSMutableArray * arr = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error]; NSLog(@"arr == %@",arr); NSData * data2 = [NSJSONSerialization dataWithJSONObject:arr options:NSJSONWritingPrettyPrinted error:&error]; NSString * str = [[[NSString alloc] initWithData:data2 encoding:NSUTF8StringEncoding] autorelease]; NSLog(@"str == %@",str); } -(NSString *)reParserJson{ NSMutableDictionary * dic=[NSMutableDictionary dictionary]; [dic setObject:@"hua" forKey:@"1"]; NSError * error=nil; NSData * data=[NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&error]; NSLog(@"data==%@",data); NSString * str=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"str==%@",str); return str; }
原文地址:http://blog.csdn.net/somerain77/article/details/25024199