TomahawkPhant
TomahawkPhant

Reputation: 1160

Restlet throwing error when JSON begins with [

I'm using Restlet to consume a json webservice and I'm getting this error:

A JSONObject text must begin with '{' at character 1

The json response I'm getting begins with a [, which seems to be causing the issue.

Is there a way to work around this?

Here is my code:

ClientResource resource = new ClientResource(
    "https://api.prosper.com/api/Listings?$top=3");
resource.setChallengeResponse(
    ChallengeScheme.HTTP_BASIC, "username", "password");
Representation representation = resource.get();
JsonRepresentation jsonRepresentation = new JsonRepresentation(representation);
JSONObject jsonObject = jsonRepresentation.getJsonObject();

Upvotes: 0

Views: 106

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 280148

Json that starts with a [ is a json array. Json that starts with { is a json object.

Use JsonRepresentation#getJsonArray()

JSONArray jsonArray = jsonRepresentation.getJsonArray();

Before you continue, familiarize yourself with the json format.

Upvotes: 2

Related Questions