
[ { "id":"1", "cardtype":"", "customer":{ "id":"11", "custnum":"aa" }, "department":{ "id":"201", "depnum":"dep1" } }, { "id":"2", "cardtype":"", "customer":{ "id":"11", "custnum":"aa" }, "department":{ "id":"201", "depnum":"dep1" } }, { "id":"3", "cardtype":"", "customer":{ "id":"11", "custnum":"aa" }, "department":{ "id":"201", "depnum":"dep1" } } ] json 格式如上,试过很多写法,都不大适合,求解。
Type founder = new TypeToken<ArrayList<bean>>(){}.getType(); List<bean> founder = gson.fromJson(jsonstring, founder);
这样的写法也不行。
1 xjtlujoe OP 懂了 gson 的 mapping 只能用来解析两层内的数据,多层不适用 |
2 cassia 2017-07-26 10:10:20 +08:00 多层没问题 |
3 cassia 2017-07-26 10:12:17 +08:00 你的 bean 没写对 import lombok.Getter; import lombok.Setter; @Getter @Setter public class OneResult { private String id; private String cardtype; private Dep department; private Customer customer; @Getter @Setter public class Dep { private String id; private String depnum; } @Getter @Setter public class Customer { private String id; private String custnum; } @Getter @Setter public class Department { private String id; private String depnum; } } |