jar包引用
com.alibaba
fastjson
1.2.46
net.sf.json-lib
json-lib
2.4
jdk15
map转jsonobject
map usermap = new hashmap<>();
usermap.put("id",2);
usermap.put("name","name");
jsonobject jsonparam = new jsonobject();
jsonparam.put("params", usermap);
map转json对象
该方法引用的是json-lib包
jsonobject jsonobject = jsonobject.fromobject(data);
map转json字符串
string userbody = json.tojsonstring(usermap);
map格式json字符串转map
string resultbody = "一个json字符串";
map userresult= json.parseobject(resultbody,map.class);
json字符串转list
string loaddata= "一个json字符串";
list
list转json数组
jsonarray array= jsonarray.parsearray(json.tojsonstring(varlist));
实体转json字符串
webserviceresult webserviceresult = new webserviceresult();
objectmapper mapper = new objectmapper();
string result = mapper.writevalueasstring(webserviceresult);