【OpenSource】【JSON】json 解析框架

来源:互联网 发布:淘宝魅族售后 编辑:程序博客网 时间:2024/06/05 04:38

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 listJsonElement 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 }

原创粉丝点击