iOS开发中Json字符串转Json对象

//把json字符串转换为Json对象的方法

-(NSDictionary*)dictionaryWithJsonString:(NSString*)jsonString {

if(jsonString ==nil) {

returnnil;

}

NSData*jsonData = [jsonStringdataUsingEncoding:NSUTF8StringEncoding];

NSError*err;

NSDictionary*dic = [NSJSONSerializationJSONObjectWithData:jsonData

options:NSJSONReadingMutableContainers

error:&err];

if(err) {

NSLog(@"json解析失败:%@",err);

returnnil;

}

NSMutableDictionary*newdict=[[NSMutableDictionaryalloc]init];

for(NSString*keysindic)

{

if(dic[keys]==[NSNullnull])

{

[newdictsetObject:@" "forKey:keys];

continue;

}

[newdictsetObject:[NSStringstringWithFormat:@"%@",dic[keys]]forKey:keys];

}

returnnewdict;

}

你可能感兴趣的:(iOS开发中Json字符串转Json对象)