Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java &引用;rss没有值“;,尽管它';很明显在那里_Java_Android_Xml_Json_Rss - Fatal编程技术网

Java &引用;rss没有值“;,尽管它';很明显在那里

Java &引用;rss没有值“;,尽管它';很明显在那里,java,android,xml,json,rss,Java,Android,Xml,Json,Rss,我试图在一个Android项目中阅读CNN的RSS提要。到目前为止,一切进展顺利。我成功地建立了连接,并将整个XML文件作为一个字符串检索。然后我尝试创建一个JSON对象并对其进行解析。然而,它的某些部分无法阅读。我试图阅读的XML是这样的 查看来源: 为了简化并使一切更加清晰,我附加了一张在JSON对象编辑器中查看的RSS提要的图片: 所以代码是这样的 //It successfully converts the text to JSON JSONObject jObj = new JSON

我试图在一个Android项目中阅读CNN的RSS提要。到目前为止,一切进展顺利。我成功地建立了连接,并将整个XML文件作为一个字符串检索。然后我尝试创建一个JSON对象并对其进行解析。然而,它的某些部分无法阅读。我试图阅读的XML是这样的

查看来源:

为了简化并使一切更加清晰,我附加了一张在JSON对象编辑器中查看的RSS提要的图片:

所以代码是这样的

//It successfully converts the text to JSON
JSONObject jObj = new JSONObject(responseText);

String respTime = jObj.getString("responseTime");
//It successfully prints the responseTime
System.out.println("Response time is: " + respTime);

JSONObject respHeader = jObj.getJSONObject("responseHeaders");
String date = respHeader.getString("date");
//It successfully prints the date as well
System.out.println("Date is: "+ date);


//However it says no value for rss found
JSONObject rssObj  = jObj.getJSONObject("rss");
JSONObject channelObj = rssObj.getJSONObject("channel");
JSONArray itemArr = channelObj.getJSONArray("item");

“responseTime”、“responseHeaders”和“rss”在XML文件的层次结构方面都是等价的,正如您从我引用的图像中看到的。因此,虽然我能够阅读“responseTime”和“responseHeaders”,但为什么它说“rss”没有价值,因此我无法访问它的任何子项?

我找到了答案。实际的JSON对象字符串,即responseText,与XML文件中显示的内容不同。这是不一样的,我花了时间才意识到这一点。我无法从Eclipse的logcat中复制它,因为它的缓冲区有限,所以我必须通过写入文本文件来研究它。然后我可以正确地解析它