Skip to content

Can't access array after parse #94

Open
@mvlaran

Description

@mvlaran

There is an API that responds with JSON arrays. The response can be an empty array [] or [{...}, {...}, {...}] an array with one or more objects. Here it its one example of a response:

[{
  "entityId": "74c975351-3fe7-4a5c-91d6-15b73e1304cd",
  "entityCoords": {
    "x": 100,
    "y": 825,
    "offsetX": 160,
    "offsetY": 215
  }
}]

As I receive the response from the API, I try to parse the string so I can verify how many objects are there, if any, and, for each one, get the information I need:

  Set JSONResponse = New JSONObject
  JSONResponse.Parse(APIResponse)

There is no error with that, but I can't access the JSONResponse object, no matter how I try, but if I write it down, I can see its contents, so JSONResponse.Write gives:

{"data":[{"entityId": "74c975351-3fe7-4a5c-91d6-15b73e1304cd","entityCoords": {"x": 100,"y": 825,"offsetX": 160,"offsetY": 215}}]}

But JSONResponse("data") is null/empty, JSONResponse.length or JSONResponse.items raises errors.

I figured out that if I parse the response in a temporary JSONObject and then, parse its serialization:

  Set JSONResponse = New JSONObject
  Set JSONTmp = New JSONObject
  JSONTmp.parse(APIResponse)
  JSONResponse.Parse(JSONTmp.serialize())

JSONResponse("data") become accessible as well I can get JSONRespose("data").length and iterate over the array, if any data is present.

Is this behaviour ok?! Or did I do something wrong in the first place?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfix-on-development-branchA fix for this issue was implemented on current development branch.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions