您的位置:首页 > Web前端 > JavaScript

【OpenSource】【JSON】json 解析框架

2017-06-27 10:17 120 查看
1. Java 的 JSON 开源类库选择比较

2. Gson 解析 1

3. Gson 解析 2

4. Gson 解析 3

位置:

1. gson on github

2. downloads at Maven Central

问题:

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
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: