标签:val mode ons ios 问题 ora comm tab print
项目需求需要传json格式到后台
字典转成JSON
AddGoodModel*model = _dataArray[i];
NSMutableDictionary*guigeDict =[NSMutableDictionary dictionary];
[guigeDict setValue:model.name forKey:@"name"];
[guigeDict setValue:model.isck forKey:@"isck"];
[guigeDict setValue:groupPrice forKey:@"groupprice"];
[guigeDict setValue:model.price forKey:@"price"];
[guigeDict setValue:model.storage forKey:@"storage"];
[guigeDict setValue:[NSString stringWithFormat:@"%ld",model.AddGoodID] forKey:@"id"];
[guigeDict setValue:model.commonid forKey:@"commonid"];
NSDictionary*parameter =@{@"":[[NSString alloc]initWithData:[NSJSONSerialization dataWithJSONObject:guigeDict options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding]};
注意事项:字典不能是
[guigeDict setObject:@”“ forKey:@”“]; 方式赋值,不然会出现乱码的情况
数组转成JSON
数组转成json只能转成字符串的形式,注意好像不能是可变数组,只能是不可变数组
,不然会出现问题
NSArray*jsonArray =[NSArray arrayWithArray:_NewArray];
NSString*string =[jsonArray JSONString];
注意:接收转换后的JSON格式数据一定要用相应类型接收赋值,不然会数据类型不对崩溃
ios 中 数组、字典转成json格式上传到后台,遇到的问题
标签:val mode ons ios 问题 ora comm tab print
原文地址:http://www.cnblogs.com/xiwanxiang190351/p/7028597.html