标签:
一)将NSDictionary转换成为NSData类型
NSDictionary *tempDict=[[NSDictionary alloc] initWithObjectsAndKeys:@"nihao",@"sayHeiio", @"woshizhu",@"geyan",nil];
NSData *jsonData=[self toJSONData:tempDict];
二)将NSData类型转换为Json
NSString *tramsmitData= [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
-(NSData *)toJSONData:(id)theData {
NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:theData
options:NSJSONWritingPrettyPrinted
error:&error];
if ([jsonData length] > 0 && error == nil){
return jsonData;
}else{
return nil;
}
}
标签:
原文地址:http://www.cnblogs.com/changeUniversal/p/4631343.html