2. Gson 解析 1
3. Gson 解析 2
4. Gson 解析 3
位置:
问题:
1. com.google.gson.internal.LinkedTreeMap cannot be cast to my class
{"root":
[
{"mBarcode":"123","mName":"Apfel","mPrice":"2.7"},
{"mBarcode":"456","mName":"Pfirsich","mPrice":"1.1111"},
{"mBarcode":"89325982","mName":"Birne","mPrice":"1.5555"}
]
}
JsonObject root = g.fromJson(json, JsonObject.class);
//read root element which contains list
JsonElement e = root.get("root");
//as the element is array convert it
JsonArray ja = e.getAsJsonArray();
for(JsonElement j : ja){
//here use the json to parse into your custom object
}