Home > Net >  Remove [ ] wrapping json response
Remove [ ] wrapping json response

Time:12-09

I have set up a Ktor client on my Android app and I am making a get request to some API. I am greeted with:

I/System.out: Error: Expected start of the object '{', but had 'EOF' instead

I found this SO question, which basically got me to think that I have to remove the [] that surrounds the response...

  1. I have no idea if this is what I am supposed to do
  2. Assuming it is the right path, I don't know how I would go about doing this from the android side

the response looks like this:

 [
   {
     "dateCreated": "07-22-2021",
     "comments": "Commenst",
      etc...
   }
 ]

CodePudding user response:

You can't, or at least that's not going to work the way you want it to. The [] means that the json data is an array. You have multiple json objects here. It would be trivial to delete the first and last character of the string, but then the parser will be really confused since you won't be giving it valid json.

Instead, whatever method you're using to parse the json- tell it its parsing a array of json objects rather than a single one. Then everything should work fine.

  • Related