- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图从我的 wordpress 网站获取内容。我想要指定帖子中的内容,您可以在那里看到:(理解,这个网站不是真实的,但它来自真实的网站,我只是替换了不同的标题、url 等)http://pastebin.com/PWuC8usi
我正在使用 Wordpress API (RESTFUL API)。
错误说:
Error parsing data Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
InputStream inputStream = null;
String result= null;
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(params[0]);
try {
HttpResponse response = client.execute(httpGet);
inputStream = response.getEntity().getContent();
// convert inputstream to string
if(inputStream != null){
result = convertInputStreamToString(inputStream);
Log.i("App", "Data received:" +result);
}
else
result = "Failed to fetch data";
return result;
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
private void parseJSON(String data){
try{
JSONObject jsonResponse = new JSONObject(data);
//JSONArray jsonMainNode = jsonResponse.getJSONArray("posts");
JSONArray jsonMainNode = jsonResponse.getJSONArray("content");
Log.i("App", "jsonMainNode = "+jsonMainNode);
int jsonArrLength = jsonMainNode.length();
Log.i("App", "jsonArrLength = "+jsonArrLength);
for(int i=0; i < jsonArrLength; i++) {
JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
String postTitle = jsonChildNode.getString("title");
String postUrl = jsonChildNode.getString("url");
String postDate = jsonChildNode.getString("date");
String postContent = jsonChildNode.getString("content");
tvPostTitle.setText("Page title: " +postTitle);
tvPostUrl.setText("Page URL: " +postUrl);
tvPostDate.setText("Date: " +postDate);
tvPostContent.setText("Content: " +android.text.Html.fromHtml(postContent).toString());
}
}catch(Exception e){
Log.i("App", "Error parsing data " +e.getMessage());
}
}
最佳答案
您正在解析的字符串不是 JSON 格式。
以下 fragment :
try {
String data = "<!DOCTYPE not a json data goes here ...";
JSONObject jsonResponse = new JSONObject(data);
} catch (JSONException e) {
Log.d("App", "Error parsing data " + e.getMessage());
}
会给你同样的错误信息:
Error parsing data Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
我猜您正在连接到错误的 API 端点。检查您正在使用的 URL。使用您自己的网络浏览器连接到那里。
关于android - Restful API : Unable to get information from Wordpress Website,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32084693/
Win32 的 Delphi XE5 编译器具有新的调试信息设置:有限调试信息。 有限调试信息和调试信息有什么区别? 最佳答案 某些编译器提供调试标志的变体,可提供不同级别的调试信息和优化。根据编译和
我有一个 highcharts 散点图,我想添加一些自定义功能。对于每次单击 highcharts 中的项目(单击过滤器、数据点和关闭按钮),我想将有关单击的项目的信息发送到我在下面包含的函数“s”。
我们在 Java 应用程序中更新了安全证书,突然我们开始收到下面提到的异常: java.lang.SecurityException: class "org.hibernate.cfg.Configu
我正在使用 HttpURLConnection 实例来连接到 URL。 然后我调用 getResponseCode 方法以确定连接状态。 我正在使用此方法轮询连接,直到返回的响应代码不是 1xx: H
我很难调试 ASP.NET MVC 代码。我最终按照本 website 中的描述进行操作.调试符号已加载并适用于所有 dll,但 System.Web.MVC。当我双击 stacktrace 窗口中的
好吧,我在很多应用程序上都发现了这个文本,那就是当我安装一些应用程序时需要android.permission.READ_LOGS 权限,它们显示一些文本,例如“读取敏感日志数据的权限...”我不明白
我有一个在浏览器中运行并从 Javascript 调用的小程序。有 2 个类:PortalLauncher 和 ParamSplitter,它们位于默认包中。 Javascript 调用 Portal
我在 eclipse 中使用 OSGi 项目运行 JUnit 测试,我遇到了这个异常: java.lang.SecurityException: class "org.eclipse.core.run
我正在开发一个给 PDF 加水印的小工具,它适用于某些 PDF,但对某些其他 PDF 会崩溃。 我正在使用 iText 库和 bouncycaSTLe(依赖项) pom.xml:
很抱歉,我不知道这是否是属于mathoverflow的数学问题,还是属于这里的计算机科学问题。 就是说,我相信我理解基本的difference between data, information, a
在什么情况下“反文档频率”在信息检索中不起作用? 最佳答案 如果您不希望在系统中权衡稀有术语而不是频繁出现的术语,则可能不希望使用IDF。此外,计算idf是一项昂贵的操作。从以下事实可以明显看出这一点
我正在尝试计算 Average Precision (和 Mean Average Precision )在 Oxford Building image dataset 上. 下面是他们提供的用于计算
信息隐藏如何帮助解耦构成系统的模块? 最佳答案 封装(信息隐藏)允许您只向外界公开绝对最小值。这意味着您可以在不影响客户的情况下将未公开的位更改为您心中的内容。 一个例子。假设您已经实现了一个将字符串
想象一下,在接下来的 10 年里,你拥有世界上所有的 super 计算机。你的任务是尽可能无损地压缩 10 部完整的电影。另一个标准是普通计算机应该能够即时解压缩,并且不需要花费太多的 HD 来安装解
我生活在一个每年更改两次时间的国家。即:一年中有一段时期与 UTC 的偏移量为 -3 小时(-180 分钟),其他时期的偏移量为 -4 小时(-240 分钟) 从图形上看: |-----
在哪里可以找到有关 DrRacket 中 #:when 构造的文档? 这是完整的示例: (define (problem_9 sum) (for*/first ([c (in-range 3 (-
有人知道在网站上查找最相关的联系信息的脚本/食谱/库吗? 一些可能的情况: 在个人网页上查找联系电话号码 在博客上查找所有者电子邮件地址 查找联系页面的网址 最佳答案 查看WSO2's Mashup
你们如何管理信息溢出?你们都用什么工具?有用的工具之一是 RSS 提要阅读器。是否有任何机构使用任何其他工具或任何其他方式来有效管理信息? 最佳答案 做一个信息势利小人。 如果该博客没有绝对震撼您的世
我最近根据 Artima Inside the JVM 2-nd Ed 阅读了有关 JVM 规范的内容。其中一章提到了 Java 运行时中的类型存储,内容如下: An instance of clas
我已阅读 Permuterm indexes stanford 网站上的页面,但是我仍然无法弄清楚我们如何从以下地址到达:*X*至 X* . 那么$在哪里? ? 我可以得到这些: For X, loo
我是一名优秀的程序员,十分优秀!