示例:
@JavascriptInterface
public String getBookDetail() {
JSONObject json = new JSONObject();
try {
json.put("bookId", bookInfo.getBookId());
json.put("bookName", bookInfo.getBookName());
json.put("description", bookInfo.getDescription());
JSONArray array = new JSONArray();
for (ChapterInfo info : bookInfo.getChapterList()) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("chapterId", info.getChapterId());
jsonObject.put("chapterName", info.getChapterName());
jsonObject.put("status", info.getDownloadState());
array.put(jsonObject);
}
json.put("chapters", array.toString());
} catch (JSONException e) {
e.printStackTrace();
}
return json.toString();
}