- NSDictionary *song = [NSDictionary dictionaryWithObjectsAndKeys:@"i can fly",@"title",@"4012",@"length",@"Tom",@"Singer", nil];
- if ([NSJSONSerialization isValidJSONObject:song])
- {
- NSError *error;
- ///将JSON数据写为NSData数据
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:song options:NSJSONWritingPrettyPrinted error:&error];
- NSString *json =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
- NSLog(@"json data:%@",json);
- }
Foundation对象(字典,数组等)转换为json串
猜你喜欢
转载自my.oschina.net/fllKevin/blog/1806084
今日推荐
周排行