JSONException: End of input at character 0

前端 未结 3 2023
心在旅途
心在旅途 2020-12-20 05:48

i am trying to get JSON values from server. I don\'t know what is wrong with my code. I am using AsyncTask and here is my code in doInBackground

相关标签:
3条回答
  • 2020-12-20 06:05

    The reason why you get this error is because you attempt to access the response more than once. For example lets lets say you do a log with the response, then create a json object with the same response object, it will trigger this one time acees error.

    0 讨论(0)
  • 2020-12-20 06:10

    You are probably getting a blank response. Its not null but the jsontext is empty. So you are getting this error and not a Nullpointer exception

    Are you sending right parameters to server.Also Check url respond to POST requests or not.

    0 讨论(0)
  • 2020-12-20 06:16

    Check if the response is not empty before process the JSON:

    if (response.success()) {
        if (response.getData() == null) {
            return null;
        } else if (response.getData().length() <= 0){
            return null;
        }
    
        try {
            // Logic
    
    0 讨论(0)
提交回复
热议问题