错误
对于返回数据次采用
JSONObject jsonObject = new JSONObject(responseData);
进行解析, android studio控制台报错
org.json.JSONException: Value [{"id":10,"userId":6,"adminId":5,"content":"7777","state":-1,"image1":"\/9j\/4AAQSkZJRg
详细错误
2022-10-02 21:07:39.622 20758-21864/com.example.electronicmall W/System.err: org.json.JSONException: Value [{"id":10,"userId":6,"adminId":5,"content":"7777","state":-1,"image1":"\/9j\/4AAQSkZJRgABAQAAAQABAAD\/4gJASUNDX1BST0ZJTEUAAQEAAAIwAAAAAAIQAABtbnRyUkdC\nIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAA\nAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlk\nZXNjAAAA8AAAAHRyWFlaAAABZAAAABRnWFlaAAABeAAAABRiWFlaAAABjAAAABRyVFJDAAABoAAA\nAChnVFJDAAABoAAAAChiVFJDAAABoAAAACh3dHB0AAAByAAAABRjcHJ0AAAB3AAAAFRtbHVjAAAA\nAAAAAAEAAAAMZW5VUwAAAFgAAAAcAHMAUgBHAEIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFhZWiAA\nAAAAAABvogAAOPUAAAOQWFlaIAAAAAAAAGKZAAC3hQAAGNpYWVogAAAAAAAAJKAAAA+EAAC2z3Bh\ncmEAAAAAAAQAAAACZmYAAPKnAAANWQAAE9AAAApbAAAAAAAAAABYWVogAAAAAAAA9tYAAQAAAADT\nLW1sdWMAAAAAAAAAAQAAAAxlblVTAAAAOAAAABwARwBvAG8AZwBsAGUAIABJAG4AYwAuACAAMgAw\nADEANgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP\/bAEMAAQEBAQEBAQEBAQEBAQEBAQEBAQ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0jQT5xi5S9\nC3kMVDfine6yAoLepvfw7ryp4TlcYOc\/tRPiEL4kJsmd7TIYqeE5RWDq9qKJqd8+sau1L0GeSKOl\n5qcTRjSMXKXoH2R90tdDyJ03HkAN8ybl4ydKn2uQf9qJrXlY75D36ZMnX4uQf9qD\/wCIc8Sl6DNX\nS\/Ccosh43k\/bbEQlS9C3lzlHROVxetuN5wxPOAOm1NbxkT97zY1anh3nOkfex7eg5Xf+aW756X7J\n5c27\/wBqC2zwrxHw+4f6Stl\/Ce8U3utqNt1O0AdUak1CQ7xfpA5+FG4EqJH3ue0coSl3c\/S4Mv4T\nl0bx\/wDVBV4101eJqV6Ydl\/+txe44osrmeAOr6VC+9i2H5B5KaTWW3teY5CvpQ9MOy\/2uQVyd\/qv\nNDD7Q7\/a09Lgl\/ZFBXHn+F6tuHTxAHV7KiPgi8x6oznfzHJMpekE9KElulfJGgvvuO8nusqB\/wA6\nr3\/Uvxbu6oVNMY+RzcAB1eBMpJb8T37H0wO0cu6Z6bjLmy\/94Xd1XqfZrjdCDttA2G9130vnd17x\njRZoqyuvMO238y6vKj5AbZA4AAAATiYBOAAOABOAAAcBOAHAAAACcAAAC3udKRaJqmqlfUqMTRvF\nQk6V0uE+JtjuLg7aXKhmunaWdrwc89O8SKms6qp2AqF6UTKjJWStcSElXg0HGFe6yYckylpRRwc+\nDujYNonpDu8Zn40UkJKvh1PS6D46u5U+LZ1FOvnyAJx4mqj8T3bHUwO0AORIAhlT4tnUfIAkAj4A\nACQAAAAOAAAAHadMV3IPQiTpiu5B6AHAkAj4kAAA4CNN+rqDwAAcAAAAAB9Jsx4+qQAfAAAAAcAA\nAHAAAAH1KnxbOo+QnAAHAkAj4kAAAAAAAOAnDgAAAAAAJAI+AASAAAAAAAAAcAAAAAABwAE4cAAA\nAAA
2022-10-02 21:07:39.625 20758-21864/com.example.electronicmall W/System.err: at org.json.JSON.typeMismatch(JSON.java:112)
2022-10-02 21:07:39.625 20758-21864/com.example.electronicmall W/System.err: at org.json.JSONObject.<init>(JSONObject.java:168)
2022-10-02 21:07:39.625 20758-21864/com.example.electronicmall W/System.err: at org.json.JSONObject.<init>(JSONObject.java:181)
2022-10-02 21:07:39.625 20758-21864/com.example.electronicmall W/System.err: at com.example.electronicmall.test.All.AllBugActivity$1$2$1$1$1.onResponse(AllBugActivity.java:372)
2022-10-02 21:07:39.625 20758-21864/com.example.electronicmall W/System.err: at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:168)
2022-10-02 21:07:39.625 20758-21864/com.example.electronicmall W/System.err: at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
2022-10-02 21:07:39.625 20758-21864/com.example.electronicmall W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2022-10-02 21:07:39.625 20758-21864/com.example.electronicmall W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2022-10-02 21:07:39.625 20758-21864/com.example.electronicmall W/System.err: at java.lang.Thread.run(Thread.java:929)
解决
对于json数据的解析, 将
JSONObject jsonObject = new JSONObject(responseData);
改为
JSONArray jsonArray = new JSONArray(responseData);
for(int i = 0; i < jsonArray.length(); i++){
JSONObject jsonObject=jsonArray.getJSONObject(i);
// code
}
原因
观察数据返回格式, 为数组类型, 因此先使用 J S O N A r r a y JSONArray JSONArray对字符串数组对象解析后, 在对单个字符串进行 j s o n json json解析
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈