json字符串转json,并从中获取某些值

 

 

String result = iUserService.getOrgInfoFromMDM();

 

JSONObject json = JSONObject.parseObject(result);

String str = json.getString("errorCode");

if(StringUtil.isNotEmpty(str) && str.equals("000000")){

JSONArray data = json.getJSONArray("data");

String unitLongtxt = data.getJSONObject(0).getString("UNIT_LONGTXT");

String deptLongtxt = data.getJSONObject(0).getString("DEPT_LONGTXT");

String unitMdcode = data.getJSONObject(0).getString("UNIT_MDCODE");

String deptMdcode = data.getJSONObject(0).getString("DEPT_MDCODE");

map.put("mdmFlag", "suc");

map.put("unitLongtxt", unitLongtxt);

map.put("deptLongtxt", deptLongtxt);

map.put("unitMdcode", unitMdcode);

map.put("deptMdcode", deptMdcode);

}else{

map.put("mdmFlag", "fail");

}

 

 

 

 

 

 

 

 

 

 

 

package sgcc.ydifp.qx.app;

import java.util.HashMap;
import java.util.Map;

import sgcc.ydifp.core.utils.HttpClientUtils;

public class TestMdm {
    public static void main(String[] args) {
        Map map = new HashMap();
        map.put("MDCODE", "1000");
        map.put("MDMID", "0");
        String str = HttpClientUtils.doPost("http://192.168.43.81:8080/nwjc/mdm/mdmquery", "{\"MDCODE\":\"1000\",\"MDMID\":\"0\"}", null, "utf-8");//("http://192.168.43.81:8080/nwjc/mdm/mdmquery", map);
        System.out.println(str);
    }
}
 

你可能感兴趣的:(Java)