Sarah Sarah - 1 year ago 145
JSON Question

OkHttp3 doesn't load all json data from server

Im going to take all user data from server in json format. the php generate code cool but i can not get all json in okhttp Response. in fact it just load part of json not all of them.

plus: the reason i use this code is that i want to take all user data from the server in login process.
here is my code in

import android.os.AsyncTask;
import android.util.Log;


import java.util.ArrayList;
import java.util.List;

import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

* Created by Android on 7/21/2016.
public class SelectAll_INFO_NetworkCallTask extends AsyncTask <String,Void,String>{
public static List<product> listOfProduct=new ArrayList<>();
public static List<Suggestion> listOfSuggestion=new ArrayList<>();
public static user myUser=new user();

public user getUser=new user();
private OkHttpClient client=new OkHttpClient();
String Result="";
public SelectAll_INFO_NetworkCallTask(user user)
this.getUser = user;

protected String doInBackground(String... params) {

try {
RequestBody requestBody;
requestBody = new MultipartBody.Builder()
.addFormDataPart("action", getUser.getStatus())

Request request = new Request.Builder()

Response response = client.newCall(request).execute();


return Result;

} catch (IOException e) {

return null;

protected void onPostExecute(String o) {

Log.d("Output is:",o);


and this is how do i call it:

public void RegForm(View view)
/* Intent intent=new Intent(this,RegisterUserActivity.class);
user myUser=new user();
SelectAll_INFO_NetworkCallTask infoCallTask=new SelectAll_INFO_NetworkCallTask(myUser);

and also this is the expected and gotten data i shared on gist

Answer Source

Well first; you should not be using AsyncTask with OkHttp. OkHttp has its own asynchronous callback:

client.newCall(request).enqueue(new Callback() {

    public void onFailure(Call call, IOException exception) {

    public void onResponse(Call call, Response response) {
        // Handle response


Secondly, to answer your question; logcat has a maximum message output that is device dependent. Therefore, outputting any string that is longer than that maximum will be truncated. So, OkHttp is receiving the entirety of the response, logcat just cannot display all of it in one message.