项目需求需要传json格式到后台
字典转成JSON
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #000000 }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #000000; min-height: 21.0px }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #6122ae }
span.s1 { }
span.s2 { color: #3c828b }
span.s3 { color: #539aa4 }
span.s4 { color: #000000 }
span.s5 { color: #3e1e81 }
span.s6 { color: #c81b13 }
span.s7 { color: #6122ae }
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"];
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #1e9421 }
span.s1 { }
NSDictionary*parameter [email protected]{@"":[[NSString alloc]initWithData:[NSJSONSerialization dataWithJSONObject:guigeDict options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding]};
注意事项:字典不能是
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #000000 }
span.s1 { }
[guigeDict setObject:@”“ forKey:@”“]; 方式赋值,不然会出现乱码的情况
数组转成JSON
数组转成json只能转成字符串的形式,注意好像不能是可变数组,只能是不可变数组
,不然会出现问题
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #000000 }
span.s1 { }
span.s2 { color: #6122ae }
span.s3 { color: #3e1e81 }
span.s4 { color: #539aa4 }
span.s5 { color: #294c50 }
NSArray*jsonArray =[NSArray arrayWithArray:_NewArray];
NSString*string =[jsonArray JSONString];
注意:接收转换后的JSON格式数据一定要用相应类型接收赋值,不然会数据类型不对崩溃