我想从不同的博客中提取数据。我已经使用文章提取器完成了此操作,但现在我必须将其转换为 json 格式以存储到 MongoDB 中。我的程序将整篇文章作为字符串返回,如下所示:
String news=ArticleExtractor.INSTANCE.getText(doc);
如何将其转换为json格式?
URL url;
url = new URL("http://blogs.timesofindia.indiatimes.com/mellowdrama/entry/india-needs-a-law-against-community-crime");
InputSource is = HTMLFetcher.fetch(url).toInputSource();
BoilerpipeSAXInput in = new BoilerpipeSAXInput(is);
TextDocument doc = in.getTextDocument();
news=ArticleExtractor.INSTANCE.getText(doc);
System.out.println(news);
JSONObject jsonObj = new JSONObject(news);
最后一行显示错误...错误是
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The constructor JSONObject(String) is undefined
at Article_ext.main(Article_ext.java:39)
最佳答案
关于java - java中将字符串转换为json格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21349568/