Note that there are some explanatory texts on larger screens.

plurals
  1. POReading Gson from json string
    primarykey
    data
    text
    <p><strong>JSON Response String:</strong></p> <pre><code>{ "1": { "registered_name": "Manchester Cars", "search_tag": null, "town": "Manchester", "distance": "1.03782874345779", "capacity": 4, "first_address_line": null, "price": "165.00", "cost_per_person": "165.00", "trip_direction": 1, "mco_id": "826", "tag": "" }, "2": { "registered_name": "Avon Cars", "search_tag": null, "town": "Solihull", "distance": "3.39530396461487", "capacity": 4, "first_address_line": null, "price": "140.82", "cost_per_person": "140.82", "trip_direction": 1, "mco_id": "670", "tag": "" }, "3": { "registered_name": "BBS Executive", "search_tag": null, "town": "Birmingham", "distance": "11.7371127605438", "capacity": 4, "first_address_line": null, "price": "186.17", "cost_per_person": "186.17", "trip_direction": 1, "mco_id": "615", "tag": "" }, "4": { "registered_name": "Sky Cars", "search_tag": null, "town": "Birmingham", "distance": "14.4878869056702", "capacity": 4, "first_address_line": null, "price": "179.13", "cost_per_person": "179.13", "trip_direction": 1, "mco_id": "822", "tag": "" }, "": { "registered_name": "Eco Cars Manchester", "search_tag": null, "town": "Stockport", "distance": "9.5043933391571", "capacity": 4, "first_address_line": null, "price": "155.00", "cost_per_person": "155.00", "trip_direction": 1, "mco_id": "774", "tag": "" } } </code></pre> <p>I want to convert this json response, i am using following GSON code but failed to convert,</p> <p><strong>Tried Solution 1</strong></p> <pre><code>Gson gson = new Gson(); Item[] itemList = gson.fromJson(jstring, Item[].class); Type collectionType = new TypeToken&lt;Collection&lt;Item&gt;&gt;(){}.getType(); List&lt;Item&gt; enums = gson.fromJson(jstring, collectionType); </code></pre> <p><strong>Tried Solution 2</strong></p> <pre><code>Gson gson = new Gson(); Item[] itemList = gson.fromJson(jstring, Item[].class); </code></pre> <p>Where jstring is json response printed above.</p> <p><strong>Failed:</strong> java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload