json java 转义_java解析json,带转义字符的json

一:解析普通json

1:不带转化字符

格式{"type":"ONLINE_SHIPS","message":{"currentTime":1400077615368,"direction":0,"id":1,"latitude":29.5506,"longitude":106.6466}}

JSONObject jsonObject = new JSONObject(jsonstr).getJSONObject("message");

System.out.println("currentTime:"+jsonObject.get("currentTime"));

System.out.println("direction:"+jsonObject.get("direction"));

System.out.println("latitude:"+jsonObject.get("latitude"));

System.out.println("longitude:"+jsonObject.get("longitude"));

jsonarray

JSONObject jo = ja.getJSONArray("cargoList").getJSONObject(0);

2:带转义字符的json格式

{"type":"ONLINE_SHIPS","message":"{\"currentTime\":1400077615368,\"direction\":0,

你可能感兴趣的:(json,java,转义)