JSON Object(如NSDictionary,NSArray)转化为JSON格式的NSString #iOS开发

     NSString *string = [self jsonObjectToJSONString:inputDataDic];

 -(NSString*)jsonObjectToJSONString:(id)object
{
if ([NSJSONSerialization isValidJSONObject:object]) {
NSString *jsonString = nil;
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object
options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
error:&error];
if (!jsonData) {
NSLog(@"Got an error: %@", error);
} else {
jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
return jsonString;
}else{
return nil;
} }
上一篇:Java Spring MVC项目搭建(二)——项目配置


下一篇:Python第三周第一次作业中关于工程目录各种导入的模拟学习