1. 打包

JSONObject jsonObject = new JSONObject();
jsonObject.put("code", "200");
jsonObject.put("message", "成功");
JSONArray deviceTypeArray = new JSONArray();

List list =产生一个List;
for(Object o:list) {
  JSONObject dtJson = new JSONObject();
  dtJson.put("name", (Integer)o);
  deviceTypeArray.add(dtJson);
}

jsonObject.put(“data”,deviceTypeArray);

return jsonObject.toJSONString();

2.解析

String s = 返回一个String;
JSONObject jo = JSONObject.parseObject(s);

String ss = jo.getString("message");
System.out.println(ss);

JSONArray ja = jo.getJSONArray("data");
for(Object j:ja) {
  Integer type = ((JSONObject) j).getInteger("name");
  System.out.println("-------->"+type);
}

相关文章:

  • 2021-09-14
  • 2021-11-18
  • 2021-11-20
  • 2021-09-14
  • 2021-12-27
  • 2021-09-14
  • 2021-09-14
  • 2021-11-18
猜你喜欢
  • 2021-09-14
  • 2021-09-14
  • 2021-08-13
  • 2021-09-14
  • 2021-09-14
  • 2021-09-14
  • 2021-12-26
  • 2021-09-24
相关资源
相似解决方案