GSON uses POJO classes to parse JSON into java objects.
Create a java class containing variables with names and data type, the same as the keys of the JSON object. I think the JSON you get is not in the correct format.
Class SupplyPrice{ double CAD; double CHF; double TRY } Class SupplyPriceContainer{ ArrayList<SupplyPrice> supplyPrice; }
And your JSON should be
{ "CAD": 78, "CHF": 54600.78, "USD": 20735.52 } { "supplyPrice": [{ "CAD": 78, "CHF": 0, "USD": 0 }, { "CAD": 0, "CHF": 54600.00, "USD": 0 }, { "CAD": 0, "CHF": 0, "USD": 20735.52 }] }
Then you can use GSON `fromJson (String pJson, class pClassType) to convert to a JAVA object
Gson gson = new Gson() ArrayList<SupplyPrice> suplyPrices = gson.fromJson(pJsonString, SupplyPrice.class);
Now you can use arraylist to get data.
bpr10 source share