Gson从地图列表解析.如何? [英] Gson parsing from List of Maps. How?

查看:150
本文介绍了Gson从地图列表解析.如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSON格式解析存在问题

Have an issue with JSON format parsing

{
    "retval": [
        {
            "DocumentEntityCD": "AccOperation",
            "DocumentType": "Document Accounting operation",
            "DocNumber": "12345",
            "DebitAccountCode": "201",
            "CreditAccountCode": "201",
            "Amount": 75.5
        },
        {
            "GeneralJournalID": "5NE5DsWHo0GD_VkiJO_a1Q",
            "DocumentUID": "sV6Pqw-_CkuAtiZsuzZNcA",
            "Date": "2012051521",
            "DocumentEntityCD": "AccOperation",
            "DocumentType": "Document Accounting operation",
            "Amount": 555
        }
    ],
    "time": 0
}

Object应该看起来像Gson才能正确解析?

How Gson should Object should looks like for right parsing?

推荐答案

我会用这样的类进行解析:

I would parse with a class like this:

   public static class Container{
      public List<Map> retval;
      public Integer time;
   }

因此轻松提取您感兴趣的值.

so that extracting the values you are interested in is quite easy.

   Gson g = new Gson();
   Container c = g.fromJson(json, Container.class);
   System.out.println(c.retval.get(0).get("DocNumber"));

这篇关于Gson从地图列表解析.如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆