我正在尝试将 json 字符串解析为 java 对象。目前代码是手动读取文件并生成java对象。但是,我希望将实现带到 gson。
这是我从 Web 服务调用中收到的 json:
{ "comment": [
"This file is used to define the behavior for the elements parsed.",
"Each entry in the file will have the format of element:name, skip:bool",
"If SkipFlag is true, it means that element need not be processed.",
"Convention used for elements and rule names is camelCase"
],
"rules": [ { "element": "html", "skip": true },
{ "element": "head", "skip": true },
{ "element": "head", "skip": true },
{ "element": "body", "skip": true }
]
}
我需要忽略评论并转换规则。这是我试图为规则 java 对象定义的 java 类型:
// Arraylist < Map < elementname, Map < name, value > > >
ArrayList< Map<String, Map<String, String> > > rules;
有没有一种简单的方法可以用 gson 做到这一点?