JSONException: Value of type java.lang.String cannot be converted to JSONObject

前端 未结 14 2375
别那么骄傲
别那么骄傲 2020-11-22 07:10

I have a JSON file with 2 JSON-Arrays in it: One Array for routes and one Array for sights.

A route should consist of several sights where the user gets navigated to

14条回答
  •  眼角桃花
    2020-11-22 07:49

    In my case, my Android app uses Volley to make a POST call with an empty body to an API application hosted on Microsoft Azure.

    The error was:

    JSONException: Value 

    iisnode of type java.lang.String cannot be converted to JSONObject

    This is a snippet on how I was constructing the Volley JSON request:

    final JSONObject emptyJsonObject = new JSONObject();
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, emptyJsonObject, listener, errorListener);
    

    I solved my problem by creating the JSONObject with an empty JSON object as follows:

    final JSONObject emptyJsonObject = new JSONObject("{}");
    

    My solution is along the lines to this older answer.

提交回复
热议问题