“Expected BEGIN_OBJECT but was STRING at line 1 column 1”

前端 未结 14 2206
误落风尘
误落风尘 2020-11-22 01:11

I have this method:

public static Object parseStringToObject(String json) {
    String Object = json;
    Gson gson = new Gson();
    Object objects = gson.f         


        
相关标签:
14条回答
  • 2020-11-22 01:39

    Don't use jsonObject.toString on a JSON object.

    0 讨论(0)
  • 2020-11-22 01:39

    I had a case where I read from a handwritten json file. The json is perfect. However, this error occurred. So I write from a java object to json file, then read from that json file. things are fine. I could not see any difference between the handwritten json and the one from java object. Tried beyondCompare it sees no difference. I finally noticed the two file sizes are slightly different, and I used winHex tool and detected extra stuff. So the solution for my situation is, make copy of the good json file, paste content into it and use.

    0 讨论(0)
  • 2020-11-22 01:46

    In my case, my custom http-client didn't support the gzip encoding. I was sending the "Accept-Encoding: gzip" header, and so the response was sent back as a gzip string and couldn't be decoded.

    The solution was to not send that header.

    0 讨论(0)
  • 2020-11-22 01:50

    Maybe your JSON Object is right,but the response that you received is not your valid data.Just like when you connect the invalid WiFi,you may received a strange response < html>.....< /html> that GSON can not parse.

    you may need to do some try..catch.. for this strange response to avoid crash.

    0 讨论(0)
  • 2020-11-22 01:51

    Even without seeing your JSON string you can tell from the error message that it is not the correct structure to be parsed into an instance of your class.

    Gson is expecting your JSON string to begin with an object opening brace. e.g.

    {
    

    But the string you have passed to it starts with an open quotes

    "
    
    0 讨论(0)
  • 2020-11-22 01:51

    if your json format and variables are okay then check your database queries...even if data is saved in db correctly the actual problem might be in there...recheck your queries and try again.. Hope it helps

    0 讨论(0)
提交回复
热议问题