【发布时间】:2020-10-25 13:42:16
【问题描述】:
我有一个名为 object 的 JSONObject。
它有很多书籍类的对象。
这是第一个元素的打印:
I/System.out: {"id":"1","author":"Paula Hawkins","description":"EVERY DAY THE SAME\n\nRachel Soon she is deeply entangled not only in the investigation but in the lives of everyone involved. Has she done more harm than good?","publication_date":"13\/01\/2015","title":"The girl on the train","url_image":"hawkins.jpg"}
想获取id、作者等,但不知道怎么获取。
Gson gson = new Gson();
JSONArray mainObject = new JSONArray(total.toString());
for (int i = 0; i < mainObject.length(); i++) {
JSONObject object = mainObject.getJSONObject(i);
int id = object.getInt("id"); //This will have the value of the id
String author = object.getString("author");
String description = object.getString("description");
String publication_date = object.getString("publication_date");
String title = object.getString("title");
String url_image = object.getString("url_image");
}
System.out.println(mainObject.get(1));
for(int i =0; i<mainObject.length(); i++){
book = new Book();
}
这是我如何创建对象的代码。
有什么想法吗?
【问题讨论】: