标签:obj pretty length dict ted nsdata utf8 array using
//字符串转数组
- (id)toArrayOrNSDictionary:(NSString *)jsonData{
if (jsonData != nil) {
NSData* data = [jsonData dataUsingEncoding:NSUTF8StringEncoding];
id jsonObject = [NSJSONSerializationJSONObjectWithData:data options:NSJSONReadingAllowFragmentserror:nil];
if (jsonObject != nil){
return jsonObject;
}else{
// 解析错误
return nil;
}
}
return nil;
}
//字符串转json
- (NSString *)toJSONData:(id)theData{
NSString * jsonString = @"";
if (theData != nil) {
NSData *jsonData = [NSJSONSerializationdataWithJSONObject:theData options:NSJSONWritingPrettyPrintederror:nil];
if ([jsonData length] != 0){
jsonString = [[NSStringalloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
}
return jsonString;
}
标签:obj pretty length dict ted nsdata utf8 array using
原文地址:https://www.cnblogs.com/-ios/p/14610543.html