dkfr.net
当前位置:首页 >> ios json字符串转字典 >>

ios json字符串转字典

NSError *error;NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data options:NSJSONWritingPrettyPrinted error:&error];NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

NSError *error; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data options:NSJSONWritingPrettyPrinted error:&error]; NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

- (void)viewDidLoad { [super viewDidLoad]; NSDictionary *dict = @{@"aaa":@"11",@"bb":@"22",@"cc":@"33"}; NSString *str = [self dictionaryToJson:dict]; NSDictionary *dict1 = [self dictionaryWithJsonString:str]; NSLog(@"%@",str);...

系统自带方法进行转码 + (NSString*)dictionaryToJson:(NSDictionary *)dic { NSError *parseError = nil; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError]; return [[...

字符串是JSON格式 调用 NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; NSError *err; NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err]...

/*! * @brief 把格式化的JSON格式的字符串转换成字典 * @param jsonString JSON格式的字符串 * @return 返回字典 */ + (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString { if (jsonString == nil) { return nil; } NSData *jso...

可以使用NSDictionary中的键值对来拼接Json数据,非常方便,也可以进行嵌套,直接上代码: //开始拼接Json字符串 NSDictionary *dataDictionary= [NSDictionary dictionaryWithObjectsAndKeys:@"mac",@"mac", @"game",@"game", @"devicetoken",@...

字典其实可以看成一个对象嘛,字典有多少字段,可以相应的给对象多少属性,数组是容器,容器中有多少个这样的对象

您好,很高兴为您解答。 1. 请试试下面的代码。 NSError* error; 1 2 3 4 5 6 NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error]; NSArray* latestLoans = [json objectForKey:@"l...

var data; var json='[{"CityId":18,"CityName":"西安","ProvinceId":27,"CityOrder":1},{"CityId":53,"CityName":"广州","ProvinceId":27,"CityOrder":1}]'; eval("data="+json); alert(data);

网站首页 | 网站地图
All rights reserved Powered by www.dkfr.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com