//数组转NSData
NSData *jsonData = [self toJSONData:self.contactInfosArr];
NSString *insertQuoteStr = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];;
WDLog(@"%@",insertQuoteStr);
// 将字典或者数组转化为JSON串
- (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{
WDLog(@"%@",error);
return nil;
}
}
运用runtime API
iOS 将NSArray、NSDictionary转换为JSON格式进行网络传输
http://blog.csdn.net/worldzhy/article/details/49982491