//字符串转数组
- (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;
}