美文网首页
json字符串转换

json字符串转换

作者: 米米露 | 来源:发表于2017-03-28 09:32 被阅读0次

1.json字符串转字典或数组
方法:+ (id)JSONObjectWithData:(NSData)dataoptions:(NSJSONReadingOptions)opterror:(NSError _Nullable *)error


``` javascript

NSString *jsonStr;

NSData*jsonData = [jsonStrdataUsingEncoding:NSUTF8StringEncoding];

NSError*error;

NSDictionary*dic = [NSJSONSerialization JSONObjectWithData:jsonDataoptions:NSJSONReadingMutableContainers error:&error];

2.数组或者字典转换为json字符串

方法:+ (NSData)dataWithJSONObject:(id)objoptions:(NSJSONWritingOptions)opterror:(NSError _Nullable *)error

NSData *jsonData =[NSJSONSerialization dataWithJSONObject:dicoptions:(NSJSONWritingOptions)opterror:&error];

相关文章

网友评论

      本文标题:json字符串转换

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