json是从webservice获取的
返回的格式:{"item":{"orderId":"219761"},"code":0}String json = doPost("http://192.168.2.176:8903/API/api", user);
JSONObject jsonObj = new JSONObject(json);
System.out.println(jsonObj.getString("item"));行不通,这个json格式是不是还需要包装一下,求解
返回的格式:{"item":{"orderId":"219761"},"code":0}String json = doPost("http://192.168.2.176:8903/API/api", user);
JSONObject jsonObj = new JSONObject(json);
System.out.println(jsonObj.getString("item"));行不通,这个json格式是不是还需要包装一下,求解
public static void main(String[] args) {
//{"item":{"orderId":"219761"},"code":0}
Map<String,Object> map = new HashMap<String, Object>();
TestTo item = new TestTo();
item.setOrderId("219761");
map.put("item", item);
map.put("code", 0);
JSONObject jsonObj = JSONObject.fromObject(map);
String s = jsonObj.toString();
JSONObject jsonObject = new JSONObject(s);
System.out.println(jsonObject.getString("item"));
}
}
public class TestTo {
public String orderId; public String getOrderId() {
return orderId;
} public void setOrderId(String orderId) {
this.orderId = orderId;
}
}
}我测试了下没有问题啊可以获取