map格式和string格式轉化為json格式
阿新 • • 發佈:2018-11-08
1.Map轉化為json
Map<String, Object> data;
JSONObject dataJson = new JSONObject(data);//map轉化為json
String cano= dataJson.get("CarNO");
2.String轉化為json
eg1
String results= saveorUpdateServices.execute(params,type);
System.out.println("*********results:"+results);
JSONObject dataJson = new JSONObject
/*com.alibaba.fastjson.JSONObject dataJson = new com.alibaba.fastjson.JSONObject();*/
JSONObject er= (JSONObject) dataJson.parse (results);//String轉化為json
success= Integer.valueOf(er.get("success").toString()) ;
eg2
String results = EntityUtils.toString(response.getEntity());
JsonObject
int resultCode=json.get("resultCode").getAsInt();
System.out.println("querypersonsbycar-SUCCESS:獲取人員卡資訊成功沒有資訊時的資料!\n\t資訊如下:"+json);
if(resultCode==0){
JsonElement dataItems=json.get("dataItems");