//字典转json格式字符串:
- (NSString*)dictionaryToJson:(NSDictionary*)dic
{NSError*parseError =nil;NSData*jsonData = [NSJSONSerializationdataWithJSONObject:dic options:NSJSONWritingPrettyPrintederror:&parseError];return[[NSStringalloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; }
//json格式字符串转字典:
- (NSDictionary*)dictionaryWithJsonString:(NSString*)jsonString
{if(jsonString ==nil) {returnnil; }NSData*jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];NSError*err;NSDictionary*dic = [NSJSONSerializationJSONObjectWithData:jsonData options:NSJSONReadingMutableContainerserror:&err];if(err) {NSLog(@"json解析失败:%@",err);returnnil; }return dic