com.alibaba.fastjson.JSONArray cannot be cast to com.alibaba.fastjson.JSONObject

来源:互联网 发布:p2p网络运营招聘 编辑:程序博客网 时间:2024/06/05 20:45
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.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"));

查询如下:



0 0
原创粉丝点击