我的应用程序收到错误JSONException: Unterminated character at ...,但它并不总是给出错误,尽管它非常频繁。
我不太确定是代码还是与网络问题有关的问题,因为有时它工作得很好,有时不工作,即使从服务器发送的数据与它工作时和不工作时是一样的。
我的过程是使用laravel获取后端的帖子列表,并使用API实现laravel-passport。
以下是我的laravel后端的代码,但经过简化:
$response['posts'] = Post::all();
return response()->json($response);在我的android应用程序上,我是这样读的:
JSONArray jsonArrayPosts = response.getJSONArray("posts");在我使用volley的所有网络请求中,我有以下标头:
Map<String, String> params = new HashMap<>();
params.put("Accept", "application/json");
params.put("Authorization", "Bearer " + UserSingleton.getInstance().getUser().getAccess_token());
return params;它是有效的,但相当频繁,我收到一个网络错误,在volley上说
JSONException: Unterminated character at ...
我得到的结果不一致的问题可能是什么?
发布于 2018-12-29 20:52:35
试试这个流程,
JsonObject jO_One=new JsonObject(response);
为阵列数据收集执行循环
for(int i=0;i<jA_One.length;i++){
JsonObject jO_Two=new JsonObject(i);
// collect your values from keys
int mobile=jO_Two.getInt("mobiles");
// now, you can store it into your
//arraylist or whatever you are using in here...
} https://stackoverflow.com/questions/53969370
复制相似问题