Json 解析之google.gson
来源:互联网 发布:淘宝店运营公司 编辑:程序博客网 时间:2024/06/05 03:44
gson json解析工具包多用于App Json数据的解析.特此写其简单实例,来熟悉其中的API
class
{
public static void main(String[] args)
{
String text = "{'msg':'请求成功','ret':0,'data':{'pageCount':4,'pagNo':'1',stationInfors:[{'name':'电站1','status':1}]}}"
JsonObject json = new JsonParser(text).getAsJsonObject();
JsonObject dataObject = json.get("data").getAsJsonObject();
JsonArray stationObject = dataObject.get("stationInfors").getAsJsonArray();
for (int i = 0;stationObject.size() ;i++ )
{
JsonObject object = stationObject.get(i).getAsJsonObject();
int status = object.get("status").getAsInt();
String name = object.get("name").getAsString();
}
}
}
class
{
public static void main(String[] args)
{
String text = "{'msg':'请求成功','ret':0,'data':{'pageCount':4,'pagNo':'1',stationInfors:[{'name':'电站1','status':1}]}}"
JsonObject json = new JsonParser(text).getAsJsonObject();
JsonObject dataObject = json.get("data").getAsJsonObject();
JsonArray stationObject = dataObject.get("stationInfors").getAsJsonArray();
for (int i = 0;stationObject.size() ;i++ )
{
JsonObject object = stationObject.get(i).getAsJsonObject();
int status = object.get("status").getAsInt();
String name = object.get("name").getAsString();
}
}
}
0 0
- Json 解析之google.gson
- 解析json之com.google.gson.Gson
- 解析json之com.google.gson.Gson
- 解析json之com.google.gson.Gson
- JSON解析之-Gson
- JSON 之GSON 解析
- JSON 之GSON 解析
- JSON 之GSON 解析
- JSON 之GSON 解析
- JSON 之GSON 解析
- Json解析之gson
- JSON 之GSON 解析
- JSON 之GSON 解析
- JSON 之GSON 解析
- JSON 之GSON 解析
- JSON 之GSON 解析
- JSON解析之Gson
- json之com.google.gson.Gson
- javaweb学习总结(二十四)——jsp传统标签开发
- loghub学习记录
- Hibernate只查询前8条记录
- struts2标签库详解
- javaweb学习总结(二十五)——jsp简单标签开发(一)
- Json 解析之google.gson
- jsp页面访问后台方法显示数据
- javaweb学习总结(二十六)——jsp简单标签标签库开发(二)
- varchar和nvarchar的区别
- mysql数据库delete数据时不支持表别名
- BigDecimal除法运算出现java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result的解决办法
- 求链式表的表长
- MindManager导图美化——线条
- 纯数字验证码