Json字符串与字典互转

#pragma mark 转换json字符串

+(NSString *)toJSON:(id)aParam

{

NSData   *jsonData=[NSJSONSerialization dataWithJSONObject:aParam options:NSJSONWritingPrettyPrinted error:nil];

NSString *jsonStr=[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

return jsonStr;

}

#pragma mark 字符串转字典

+(NSDictionary *)dicWithJSonStr:(NSString *)jsonString

{

NSData * jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];

NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];

return dic;

}

上一篇:iOS开发JSON字符串和字典互转


下一篇:002、Python中json字符串与字典转换