{"Status":0,"Key":"aaa","Data":[{"Name":"安娜","Type":5,"EName":"ANAA","Spell":"ANNA","ShortSpell":"AN","Country":"法属波利尼西亚","CountryCode":"PF","Code":"AAA","CityId":7500,"TimeZone":"-600","POIID":115243},{"Name":"安娜机场","Type":3,"EName":"ANAA AIRPORT","Spell":"ANNAJICHANG","ShortSpell":"ANJC","Country":"法属波利尼西亚","CountryCode":"PF","Code":"AAA","Datas":[{"Name":"安娜","Type":5,"EName":"ANAA","Country":"法属波利尼西亚","CountryCode":"PF","Code":"AAA","CityId":7500,"TimeZone":"-600","POIID":115243}],"POIID":116761}]}
获取到的json,怎么按想要的字段取值,存入数据库中
Article article = FastJson.getJson().parse(jsonString, Article.class);
article.save();
如果 jsonString 中的数据与 Article 的对应关系并不是严格对应字段的,可以通过 Map 作为中间转换:
Map map = FastJson.getJson().parse(jsonString, Map.class);
Article article = new Article();
article.setXxx(map.get(xxx));
article.setYyy(map.get(yyy));
article.save();