I have an API response as below:
[
{
"id": "123",
"date": "2016-12-11T12:23:34Z",
"description": "A bag of spanners",
"amount": "35.25",
"currency": "GBP"
},
{
"id": "124",
"date": "2016-12-12T01:58:59Z",
"description": "Hot chocholate",
"amount": "12.50",
"currency": "GBP"
},
{
"id": "125",
"date": "2016-12-12T06:11:06Z",
"description": "Subscriptions - Magazine",
"amount": "5.99",
"currency": "GBP"
},
{
"id": "126",
"date": "2016-12-13T10:03:17Z",
"description": "Movie rental",
"amount": "3.99",
"currency": "GBP"
}]
I tried parsing it using java as follows:
Object object = (Object) HttpRequest.getInputStreamFromUrl(ApiUtils.getTransactionsUrl(), Object.class, mContext);
Type typeMyType = new TypeToken<ArrayList<Transaction>>(){}.getType();
Gson gson = new Gson();
transactionList = gson.fromJson(object.toString(), typeMyType);
I'm getting 'JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unterminated object at line 1 column 30'
I also tried some other approaches which caused com.google.gson.internal.LinkedTreeMap cannot be cast to org.json.JSONObject
How to parse this type of JSON object?