Wad*_*ter 5 java json boilerpipe
我正在使用samppipe,看起来很棒,但我想输出JSON.我正在使用Java版本并在NetBeans中进行如下测试:
final URL url = new URL("http://mashable.com/2012/09/26/worlds-best-father-kickstarter-calendar");
System.out.println(ArticleExtractor.INSTANCE.getText(url));
Run Code Online (Sandbox Code Playgroud)
谁能告诉我我是怎么做到的?
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\" " +
"}"
}
Run Code Online (Sandbox Code Playgroud)
棘手的部分当然是获得头衔......
或者更好的是使用JSON像JSONObject这样的序列化器。
希望有帮助。