启动器
public class Launcher {
public static void main(String[] args) {
String str = "[{" +
" \"section\": {" +
" \"term\": \"Description#1\"," +
" \"tid\": \"10\"" +
" }" +
"}," +
"{" +
" " +
"}," +
"{" +
" " +
"}," +
"{" +
" " +
"}," +
"{" +
" " +
"}," +
"{" +
" " +
"}," +
"{" +
" " +
"}," +
"{" +
" " +
"}," +
"{" +
" \"section\": {" +
" \"term\": \"Description#2\"," +
" \"tid\": \"12\"" +
" }" +
"}]";
Gson gson = new Gson();
Type type = new TypeToken<List<MyObject>>(){}.getType();
List<MyObject > objList = gson.fromJson(str, type);
assert(objList != null);
for(MyObject obj : objList){
//..
}
}
}
我的对象
public class MyObject {
public Section section;
public Section getSection() {
return section;
}
}
部分
public class Section {
private String term;
private String tid;
public String getTerm() {
return term;
}
public String getTid() {
return tid;
}
}
在循环中实现 geters