Boilerpipe
不帶有JSON
序列化程序。
你可以,但是,這樣做(假設你已經提取的所有數據):
public String articleTextToJson(String article, String title, String sourceUrl) {
if (null == article) {
return "{ \"error\" : { " +
" \"message\" : \"Article did not extract\", " +
" \"code\" : 1 " +
" }, " +
" \"status\" : \"error\" " +
"}";
}
return "{ \"response\" : { " +
" \"title\" : \"" + title + "\" " +
" \"content\" : \"" + article + "\", " +
" \"source\" : \"" + sourceUrl + "\" " +
" }, " +
" \"status\" : \"success\" " +
"}"
}
最棘手的部分當然會獲得稱號......
或者更好的是使用一些JSON
串行器像JSONObject。
希望有所幫助。
如果我的回答確實有幫助,善良並將其標記爲答案... –