Exception in thread "main" java.lang.ClassCastException: com.alibaba.fastjson.JSONArray cannot be cast to com.alibaba.fastjson.JSONObject
at com.alibaba.fastjson.JSON.parseObject(JSON.java:164)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:164)
at com.lysoft.business.web.oa.ui.jh_infoPortal.ws.Impl.test.main(test.java:12)
json中类型转换问题,意思是说这样的json不对[ {} ],要使用这样的json格式{}
String str="[{\"id\":1,\"starttime\":\"2017-04-19 15:01\"}]";
str=str.replace("[", "");
str=str.replace("]", "");
因为后台传入的有这样的json[],所以我replace了。
JSONObject jsStr=JSONObject.parseObject(str);
System.out.println(jsStr.get("starttime"));
查询如下: