0
点赞
收藏
分享

微信扫一扫

怎样使用fastJson发送数组格式的Json数据


场景

之前要发送的json数据:

{"PrintContent":"CAB1DM1152CJ@2097812420006@20181010,CAB1DM1152CJ@2097812420007@20181010,CAB1DM1152CJ@2097812420008@20181010,CAB1DM1152CJ@2097812420009@20181010"}

要转换的json数据格式:

{"PrintContent":["CAB1DM1152CJ@2097812420006@20181010","CAB1DM1152CJ@2097812420007@20181010","CAB1DM1152CJ@2097812420008@20181010","CAB1DM1152CJ@2097812420009@20181010"]}

实现

项目中引入fastJson依赖

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.24</version>
</dependency>

转换之前的转换JSON实现

for (String s:qrCodeList
) {
finalBarCode+=s+",";
}
finalBarCode=finalBarCode.substring(0,finalBarCode.length()-1);
Map map=new HashMap();
map.put("Flag","2");
map.put("PrintContent",finalBarCode);
String param= JSON.toJSONString(map);

转换之后的实现

for (String s:qrCodeList
) {
finalBarCode+=s+",";
}
finalBarCode=finalBarCode.substring(0,finalBarCode.length()-1);
Map map=new HashMap();
map.put("Flag","2");
map.put("PrintContent",qrCodeList);
String param= JSON.toJSONString(map);

 

举报

相关推荐

0 条评论