json数据与map,jsonobject,string之间的转换

1.

Map map = new HashMap<>();

String str = httpRequest("http://11.11.11.12:9000/union-base/api/person/findByContactPersonId", map, "GET");

//将json字符串str转换成map类型
map = JSON.parseObject(str, Map.class);

//获取map中键为"data"的值,并转为Object
Object dataObject = map.get("data");
//将json字符串dataObject.toString()转换成JSONObject
JSONObject jsonObject=JSON.parseObject(dataObject.toString());
//获取jsonObject中键为leaderId,jobGrade的值
String visitObjLeadId = (String) jsonObject.get("leaderId");
String visitObjJobGrade = (String) jsonObject.get("jobGrade");
 
 

你可能感兴趣的:(json,java,开发语言)