我从查询中获得字母并列出国家/地区,如何制作这样的JSON? 我对此一无所知。如何创建类似的JSON?
> List=[
> {Alphabet:'B',
> Country:[
> {name: 'Belgia'}
> ]},
> {Alphabet:'I',
> Country:[
> {name: 'Indonesia'}
> ]},
> {Alphabet:'N',
> Country:[
> {name: 'Namibia'}
> ]},
> {Alphabet:'O',
> Country:[
> {name: 'Ohio'}
> ]},
> {Alphabet:'T',
> Country:[
> {name: 'Turki'},
> {name: 'Tunisia'}
> ]},
> {Alphabet:'Y',
> Country:[
> {name: 'Yaman'},
> ]} ];
我有这样的模特
> public class ListCountry {
> private String Alphabet;
> List<ListCountryObj> List;
>
> public void setAlphabet(String Alphabet){this.Alphabet= Alphabet;}
> public void setList(List<ListCountryObj> List){this.List = List;}
>
> public String getAlphabet(){return this.Alphabet;}
> public List<ListCountryObj> getList() {return List;} }
还有这个
> public class ListCountryObj {
> private String country;
>
> public void setCountry(String country){this.country = country;}
> public String getCountry(){return this.country;} }
答案 0 :(得分:0)
答案 1 :(得分:0)
List<Map<String, List<String>
通过扩展Map创建两个具有Map对象的模型。还有就是那个对象的列表。
Class A extends map { // add all the override methods
// annotate with name you want in json
String key;
// annotate with name you want in json
List<String> value
}
Class B {
List<A> listOfA;
}
确保您建立了对象A并建立了对象B。