WCF返回的序列化JSON格式 键值对形式 {"d":"result{}"}形式,需要取到标准JSON格式数据 result{}部分的string
{"d":"{"Result":[{"StorageID":"1","StorageName":"test11","Remark":null,"IfUse":false},{"StorageID":"2","StorageName":"test2","Remark":null,"IfUse":false},{"StorageID":"3","StorageName":"test4","Remark":null,"IfUse":false},{"StorageID":"4","StorageName":"testtest","Remark":null,"IfUse":false},{"StorageID":"1158732","StorageName":"test8","Remark":null,"IfUse":false},{"StorageID":"1458527","StorageName":"000--","Remark":null,"IfUse":false},{"StorageID":"1507493","StorageName":"000--0","Remark":null,"IfUse":false},{"StorageID":"3906465","StorageName":"test9","Remark":null,"IfUse":false},{"StorageID":"3912354","StorageName":"222","Remark":null,"IfUse":false},{"StorageID":"4059909","StorageName":"33","Remark":null,"IfUse":false},{"StorageID":"4110802","StorageName":"111","Remark":null,"IfUse":false},{"StorageID":"4527897","StorageName":"test5","Remark":null,"IfUse":false},{"StorageID":"4727421","StorageName":"111test","Remark":null,"IfUse":false},{"StorageID":"4751724","StorageName":"teeee","Remark":null,"IfUse":false},{"StorageID":"5127963","StorageName":"test6","Remark":null,"IfUse":false},{"StorageID":"5127964","StorageName":"test0","Remark":null,"IfUse":false}],"ErrorStatus":6,"FeedbackMessage":"test"}"}
@Test
public void test4()throws IOException, DocumentException
{
String url = "http://127.0.0.1:8080/BaseManage/GetReservoirCacheAndroid";
ParameterHashMap params = new ParameterHashMap();
params.put("dep_id",1);
String result = ServiceHelper.post(url,params);
ResponseMessage responseMessage = getResponseMessage(result);
// String json = JSONUtils.writeValueAsString(responseMessage.getContent()) ;
String json = responseMessage.getContent().toString();
System.out.println(json);
}
public static ResponseMessage getResponseMessage(String result) throws IOException {
JsonNode node= JSONUtils.readTree(result);
JsonNode vv = JSONUtils.readTree(node.path("d").getTextValue());
ResponseMessage responseMessage=new ResponseMessage();
responseMessage.setCode( vv.path("ErrorStatus").getIntValue()+"");
responseMessage.setContent(JSONUtils.writeValueAsString(vv.path("Result")) );
responseMessage.setDecription(vv.path("FeedbackMessage").getTextValue());
return responseMessage;
}
public class ResponseMessage {
private Object content;
private String decription;
private String code;
public Object getContent() {
return content;
}
public void setContent(Object content) {
this.content = content;
}
public String getDecription() {
return decription;
}
public void setDecription(String decription) {
this.decription = decription;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}
public static String writeValueAsString(Object source) throws IOException {
return objectMapper.writeValueAsString(source);
}
[{"StorageID":"1","StorageName":"test11","Remark":null,"IfUse":false},{"StorageID":"2","StorageName":"test2","Remark":null,"IfUse":false},{"StorageID":"3","StorageName":"test4","Remark":null,"IfUse":false},{"StorageID":"4","StorageName":"testtest","Remark":null,"IfUse":false},{"StorageID":"1158732","StorageName":"test8","Remark":null,"IfUse":false},{"StorageID":"1458527","StorageName":"000--","Remark":null,"IfUse":false},{"StorageID":"1507493","StorageName":"000--0","Remark":null,"IfUse":false},{"StorageID":"3906465","StorageName":"test9","Remark":null,"IfUse":false},{"StorageID":"3912354","StorageName":"222","Remark":null,"IfUse":false},{"StorageID":"4059909","StorageName":"33","Remark":null,"IfUse":false},{"StorageID":"4110802","StorageName":"111","Remark":null,"IfUse":false},{"StorageID":"4527897","StorageName":"test5","Remark":null,"IfUse":false},{"StorageID":"4727421","StorageName":"111test","Remark":null,"IfUse":false},{"StorageID":"4751724","StorageName":"teeee","Remark":null,"IfUse":false},{"StorageID":"5127963","StorageName":"test6","Remark":null,"IfUse":false},{"StorageID":"5127964","StorageName":"test0","Remark":null,"IfUse":false}]
网友评论