map如何转json(map如何转list)

map如何转json(map如何转list)E lgq httpheader 222 name photoList ssss currentUser zhang success true 2 对象转 json gson 依赖 implementati com google code gson gson 2 8 5 json 转对象 json 转 list



 

E/lgq: httpheader----…222…{“name”:“{photoList=ssss, currentUser=zhang, success=true}”}

2、

 

对象转json

========

gson依赖;implementation ‘com.google.code.gson:gson:2.8.5’

 

json转对象


 

json转list

==========

 
 
 

生成任意格式的json数据

=============

private  JSONObject createJSONObject() {

JSONObject result = new JSONObject();

result.put(“success”, true);

result.put(“totalCount”, “30”);

result.put(“okstatus”,okreString );

JSONObject user1 = new JSONObject();

user1.put(“id”, “12”);

user1.put(“name”, “张三”);

user1.put(“createTime”, “2017-11-16 12:12:12”);

JSONObject user2 = new JSONObject();

user2.put(“id”, “13”);

user2.put(“name”, “李四”);

user2.put(“createTime”, “2017-11-16 12:12:15”);

JSONObject department = new JSONObject();

department.put(“id”, 1);

department.put(“name”,“技术部”);

user1.put(“department”, department);

user2.put(“department”, department);

// 返回一个JSONArray对象

JSONArray jsonArray = new JSONArray();

jsonArray.add(0, user1);

jsonArray.add(1, user2);

result.element(“data”, jsonArray);

return result;

编程小号
上一篇 2025-02-16 20:57
下一篇 2025-02-07 18:17

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ri-ji/41738.html