我正在使用boilerpipe,它看起来很棒,但我想输出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));有人能告诉我我是怎么做的吗?
发布于 2012-11-05 23:52:23
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\" " +
"}"
}当然,最棘手的部分是获得冠军头衔。
或者最好使用像JSONObject这样的JSON序列化程序。
希望这能有所帮助。
https://stackoverflow.com/questions/12627818
复制相似问题