封包
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value1",@"key1",@"value2",@"key2",@"value3",@"key3", nil];
// isValidJSONObject判断对象是否可以构建成json对象
if ([NSJSONSerialization isValidJSONObject:dic]){
NSError *error;
// 创造一个json从Data, NSJSONWritingPrettyPrinted指定的JSON数据产的空白,使输出更具可读性。
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dicoptions:NSJSONWritingPrettyPrinted error:&error];
NSString *json =[[NSString alloc]initWithData:jsonDataencoding:NSUTF8StringEncoding];
NSLog(@"json data:%@",json);
网友评论