2016-03-02 64 views
-2
ResponseEntity<BaseDto> entity = restTemplate.getForEntity("/get/code/IN", BaseDto.class); 
    System.out.println("entity : " + entity); 
     System.out.println("entity.getBody() : " + entity.getBody()); 
    System.out.println(entity.getBody().getResponseObject()); 

按照上面休息我得到如下格式:Java的休息模板

{ 
    systemTrack= 
    { 
    createUser=admin, 
    createDate=2016-03-01 18:11:17, 
    lastUpdatedUser=admin, 
    lastUpdatedDate=2016-03-01 18:11:17 

}, 

countryCode=IN, countryName=INDIA 

} 

如何從這種格式得到的值?

回答

0

也許我不清楚我的問題,但我通過調試模式得到了解決方案。 這是一個鏈接哈希映射的格式,所以我所做的只是在下面的代碼中爲LinkedHashMap的json轉換寫了一個。

LinkedHashMap m = (LinkedHashMap) object; 
JSONObject jsonObject = new JSONObject(m);(package of org.json.JSONObject) 
and then i assigned to custom class object using 
Gson gson = new Gson(); 
String jsonString = jsonObject.toString(); 
Object obj = gson.fromJson(jsonString, type);