如何在Android

时间:2017-06-26 18:13:50

标签: android json

我正在使用Feedly API开发RSS应用程序,但返回的数据采用此格式



   {"id":"feed/http://www.engadget.com/rss-full.xml","title":"Engadget","direction":"ltr","updated":1498476244444,"alternate":[{"href":"http://www.engadget.com","type":"text/html"}],"continuation":"15cdbe215da:25ce6aa:517b1451","items":[{"fingerprint":"cd055ce2","id":"4i+1vhCwmRRLfmB7ypTnMh+ZKSvsz6Rgf0lfR0WWb0w=_15ce424eddc:2eb441d:5b78a817","keywords":["applenews","elonmusk","falcon9","gear","iridium-2","landing","launch","space","spacex","video"],"originId":"https://www.engadget.com/2017/06/26/spacex-iridium-launch-and-sea-landing/","origin":{"streamId":"feed/http://www.engadget.com/rss-full.xml","title":"Engadget","htmlUrl":"http://www.engadget.com"},"title":"SpaceX launches and lands two rockets in a single weekend","published":1498475640000,"crawled":1498476244444,"alternate":[{"type":"text/html","href":"https://www.engadget.com/2017/06/26/spacex-iridium-launch-and-sea-landing/"}],"summary":{"content":"<img src=\"http://o.aolcdn.com/hss/storage/midas/e84bbb4d11f61b8d08b2a3dd198f4790/205413876/spacex-iridium2-launch-2017-06-26-01.jpg\"><p>SpaceX's technical problems that caused an <a href=\"https://www.engadget.com/2016/09/01/spacex-falcon-9-rocket-explodes/\">explosion</a> last September seem well behind it, as it pulled off the rare feat of launching two rockets this weekend. On Friday, the Falcon 9 <a href=\"https://www.engadget.com/2017/06/23/watch-spacex-launch-land-reused-falcon-9-rocket/\">lofted</a> a Bulgarian communications satellite into orbit from Florida's Kennedy Space Center, landing the recycled first stage at sea. On Sunday, it pulled off the trick again, sending ten Iridium-2 satellites into orbit from Vandenberg Air Force Base in California. Once again, it <a href=\"http://www.spacex.com/news/2017/06/25/iridium-2-mission\">brought</a> the first stage safely back to drone ship &quot;Just Read the Instructions&quot; despite visibly rough weather and rolling seas.</p>\n<blockquote data-instgrm-captioned=\"\" data-instgrm-version=\"7\">\n<div>\n<div><div></div></div>\n<p><a href=\"https://www.instagram.com/p/BVxysOlA04j/\" target=\"_blank\">Sped up version of today's rocket landing on the Droneship Just Read the Instructions (guess it did)</a></p>\n<p>A post shared by Elon Musk (@elonmusk) on <time datetime=\"2017-06-25T21:41:15+00:00\">Jun 25, 2017 at 2:41pm PDT</time></p>\n</div>\n</blockquote>\n<p>The landing was impressively free of drama, despite the fact that you can see the barge pitching and whitecaps breaking against it. SpaceX CEO Elon Musk said that the drone ship had to be repositioned due to &quot;extreme weather&quot; and warned that launch and landing &quot;will be tight&quot; (see the full video, below).</p>\n<p>Musk pointed out new titanium grid fins used to aerodynamically maneuver the Falcon 9's first stage for the Iridium launch. Clearly visible in the landing video, they're made of &quot;a single piece of cast and cut titanium ... [and] can take reentry heat with no shielding,&quot; he tweeted.</p>\n<blockquote class=\"twitter-tweetn\" data-lang=\"en\">\n<p dir=\"ltr\" lang=\"en\">Flying with larger &amp; significantly upgraded hypersonic grid fins. Single piece cast &amp; cut titanium. Can take reentry heat with no shielding. <a href=\"https://thislink.com/SmyCCQRt2F\">https://thislink.com</a></p>\n— Elon Musk (@elonmusk) <a href=\"https://twitter.com/elonmusk/status/878821062326198272\">June 25, 2017</a></blockquote>\n<p>Iridium might be best remembered as the company behind a <a href=\"http://www.nytimes.com/2000/04/11/business/iridium-bankrupt-is-planning-a-fiery-ending-for-its-88-satellites.html\">failed</a> space internet and cellphone calling scheme. In 2007, it <a href=\"https://www.engadget.com/2007/02/18/iridium-next-plans-for-next-gen-satellite-network/\">rebooted</a> the network as &quot;Iridium Next&quot; with an 81-satellite constellation, 75 of which will be launched by SpaceX. The aim is to &quot;provide services for aviation, maritime, internet of things, terrestrial and government organizations,&quot; says SpaceX.</p>\n<p>The two launches are the closest together yet for SpaceX. The launch of the Bulgarian satellite and recovery of the first stage marked just the second time SpaceX has used (and recovered) a recycled first stage. Interestingly, the same rocket launched the first batch of 10 Iridium satellites in its virgin debut.</p>\n<p>All of that is a good sign for SpaceX, which wants to really amp up the pace of rocket launches. Key to reducing time and cost are the first stage recoveries, and so far, SpaceX has done those successfully 13 times, including eight at sea. The last time a landing failed was <a href=\"https://twitter.com/elonmusk/status/743096769001578498\">a year ago</a>, but that was already a risky attempt following a high-orbit satellite launch. Soon, SpaceX plans to launch rockets <a href=\"https://www.engadget.com/2017/02/07/spacex-rocket-launch-schedule-florida/\">every two weeks</a>, a blistering pace that may make the still-amazing spectacle old hat.</p>\n<p><iframe width=\"640\" allowfullscreen=\"\" src=\"https://www.youtube.com/embed/7tIwZg8F9b8\" height=\"360\"></iframe></p>\n<p><strong>Source: </strong><a href=\"http://www.spacex.com/webcast\" target=\"_blank\">SpaceX</a></p>","direction":"ltr"},"visual":{"processor":"feedly-nikon-v3.1","url":"http://o.aolcdn.com/hss/storage/midas/e84bbb4d11f61b8d08b2a3dd198f4790/205413876/spacex-iridium2-launch-2017-06-26-01.jpg","width":1600,"height":879,"contentType":"image/jpeg"},"canonicalUrl":"https://www.engadget.com/2017/06/26/spacex-iridium-launch-and-sea-landing/","ampUrl":"https://www.engadget.com/amp/2017/06/26/spacex-iridium-launch-and-sea-landing/","cdnAmpUrl":"https://www-engadget-com.cdn.ampproject.org/c/s/www.engadget.com/amp/2017/06/26/spacex-iridium-launch-and-sea-landing/","unread":true,"engagement":114,"engagementRate":4.56,"webfeeds":{"logo":"http://storage.googleapis.com/test-site-assets/4i-1vhCwmRRLfmB7ypTnMh-ZKSvsz6Rgf0lfR0WWb0w_ologo-14f041f5bd8","relatedLayout":"card","relatedTarget":"browser"}},{"id":"4i+1vhCwmRRLfmB7ypTnMh+ZKSvsz6Rgf0lfR0WWb0w=_15ce3dd986a:292f4bb:fe3a8465","fingerprint":"958c855","keywords":["applenews","entertainment","gaming","gear","internet","themorningafter"],"originId":"https://www.engadget.com/2017/06/26/the-morning-after-monday-june-26th-2017/","title":"The Morning After: Monday, June 26th 2017","crawled":1498471569514,"published":1498471200000,"alternate":[{"type":"text/html","href":"https://www.engadget.com/2017/06/26/the-morning-after-monday-june-26th-2017/"}],"origin":{"streamId":"feed/http://www.engadget.com/rss-full.xml","title":"Engadget","htmlUrl":"http://www.engadget.com"},"summary":{"content":"<img src=\"http://o.aolcdn.com/hss/storage/midas/91acdd2c96169cabaee8e510b5795c22/205413860/rocke.gif\"><p>It's Monday morning, and we're talking about how tweets are now official presidential statements, the problem with the console wars and Snapchat Specs made for underwater.</p>\n<p></p>\n<hr>\n<p><span>The importance of cross-platform play.</span><a href=\"https://www.engadget.com/2017/06/24/rocket-league-cross-network-play-ps4-xbox-one-interview/\">'Rocket League' will die without cross-console multiplayer<br>\n</a></p>\n<p><a href=\"https://www.engadget.com/2017/06/24/rocket-league-cross-network-play-ps4-xbox-one-interview/\"><img src=\"https://s.aolcdn.com/hss/storage/midas/9d136c657e01ade23d99b7ec88ecda0f/205413910/newsdims640.jpg\"></a></p>\n<p>All online games eventually die. But the difference between the original version of <em>World of Warcraft</em> and, say, <em>Call of Duty: Ghosts</em> is that <em>WoW</em> was more of a service on an open system (PC). Players could gradually migrate to its annual expansions and still be a part of the overall population. When it comes to <em>Rocket League</em>, developer Psyonix's Jeremy Dunham has a way to fix these fractured player bases: opening up cross-platform multiplayer. &quot;We're not trying to build six <em>Rocket Leagues</em>,&quot; he said. &quot;We're not looking forward to when <em>Rocket League 2</em> and <em>3</em> and <em>4</em> are coming out.<em> Rocket League</em> is the game we're gonna keep updating. It's important to us to keep that going, cross-generation, across multiple platforms, without sacrificing anything.&quot;</p>\n<hr>\n<p><span>The White House claims Trump's tweets are an official response to a federal committee's inquiry.<br>\n</span><a href=\"https://www.engadget.com/2017/06/24/in-2017-tweets-are-official-presidential-statements/\">In 2017, tweets are official presidential statements<br>\n</a></p>\n<p><a href=\"https://www.engadget.com/2017/06/24/in-2017-tweets-are-official-presidential-statements/\"><img src=\"https://s.aolcdn.com/hss/storage/midas/1b05d808769cb3536d5e34fc097188a/205413929/newsdims-1640.jpg\"></a></p>\n<p>Still not sure a tweet counts as an official response to a federal inquiry? Well, the White House has reaffirmed that it is. As reported by <em>Reuters</em>, the White House sent a letter to the House of Representatives Intelligence Committee claiming that a pair of Trump tweets on Thursday were the president's official word on the matter.</p>\n<hr>\n<p><span>A university in the Netherlands is building a special cycling bridge.<br>\n</span><a href=\"https://www.engadget.com/2017/06/24/3D-printed-concerete-bridge-netherlands/\">A 3D-printed bridge using reinforced concrete<br>\n</a></p>\n<p><a href=\"https://www.engadget.com/2017/06/24/3D-printed-concerete-bridge-netherlands/\"><img src=\"https://s.aolcdn.com/hss/storage/midas/8860352c265b8f97e3cab129868a5828/205413931/newsdims-2640.jpg\"></a></p>\n<p>Researchers there have started manufacturing parts for a 3D-printed cycling bridge using reinforced concrete. When finished, it'll apparently be the first bridge to use 3D-printed reinforced concrete (but not the first 3D-printed bridge using other materials -- or even concrete itself.) There's an environmental impact, too: 3D printing will seriously cut down the CO2 emissions made by concrete-cement production. The 3D printer also offers more design freedom, fabricating shapes that are much harder to produce with a mold.<br>\n</p>\n<hr>\n<p><span>No, those 'healing stickers' aren't made of NASA tech.</span><a href=\"https://www.engadget.com/2017/06/25/nasa-calls-out-goop-healing-stickers/\">Ex-NASA scientist calls Goop's 'healing stickers' a load of BS<br>\n</a></p>\n<p><a href=\"https://www.engadget.com/2017/06/25/nasa-calls-out-goop-healing-stickers/\"><img src=\"https://s.aolcdn.com/hss/storage/midas/d261871e9ff4bd63233b4ca5b0f6023a/205413933/newsdims-3640.jpg\"></a></p>\n<p>Gwyneth Paltrow's lifestyle website, Goop, tends to promote all kinds of nonsense. One of its latest recommendations, wearable stickers by a company called Body Vibes, is pretty hard to turn a blind eye to, though, because its creators claimed that it uses NASA technology. Goop wrote that the body stickers are capable of rebalancing &quot;the energy frequency in our bodies,&quot; since they're made of the &quot;same conductive carbon material NASA uses to line spacesuits&quot; to &quot;monitor an astronaut's vitals during wear.&quot; Except, as a NASA rep told <em>Gizmodo</em>, that's not true -- at all.</p>\n<hr>\n<p><span>Snapchat teams up with cruise ship for underwater footage.<br>\n</span><a href=\"https://www.engadget.com/2017/06/25/custom-spectacles-takes-snaps-under-the-sea/\">Custom Snapchat Specs can take snaps under the sea<br>\n</a></p>\n<p><a href=\"https://www.engadget.com/2017/06/25/custom-spectacles-takes-snaps-under-the-sea/\"><img src=\"https://s.aolcdn.com/hss/storage/midas/c7f69f09bf4d5978310efb12aebacb79/205413934/newsdims640+2.jpg\"></a></p>\n<p>Spectacles have made sharing marginally exciting videos on land via Snapchat easier. It also helps that you no longer need to hunt down a vending machine to snag a pair in the US. But a partnership between the social network and Royal Caribbean cruise lines will make it easy to capture footage under the sea. The SeaSeeker can record video for up to 30 minutes underwater, at depths up to 150 feet, making it perfect for scuba and free-diving. <br>\n</p>\n<h3>But wait, there's more...</h3>\n<ul>\n<li><a href=\"https://www.engadget.com/2017/06/25/facebook-presidential-ambition-zuckerberg-tour/\">Facebook, not presidential ambition, is why Zuckerberg's on tour</a></li>\n<li><a href=\"https://www.engadget.com/2017/06/25/whatsapp-news-source-reuters-study/\">WhatsApp is becoming a top news source in some countries</a></li>\n<li><a href=\"https://www.engadget.com/2017/06/24/recommended-reading-apples-original-television-aspirations/\">Recommended Reading: Apple's original television aspirations</a></li>\n</ul>","direction":"ltr"},"visual":{"processor":"feedly-nikon-v3.1","url":"http://o.aolcdn.com/hss/storage/midas/91acdd2c96169cabaee8e510b5795c22/205413860/rocke.gif","width":400,"height":266,"contentType":"image/jpeg"},"canonicalUrl":"https://www.engadget.com/2017/06/26/the-morning-after-monday-june-26th-2017/","ampUrl":"https://www.engadget.com/amp/2017/06/26/the-morning-after-monday-june-26th-2017/","cdnAmpUrl":"https://www-engadget-com.cdn.ampproject.org/c/s/www.engadget.com/amp/2017/06/26/the-morning-after-monday-june-26th-2017/","unread":true,"engagement":36,"engagementRate":0.65,"webfeeds":{"logo":"http://storage.googleapis.com/test-site-assets/4i-1vhCwmRRLfmB7ypTnMh-ZKSvsz6Rgf0lfR0WWb0w_ologo-14f041f5bd8","relatedLayout":"card","relatedTarget":"browser"}}]}
&#13;
&#13;
&#13;

我尝试了以下代码

 String response = new String(NetworkUtils.getConnectionBytes(connection.getInputStream()));
 Log.d(TAG, "Response: " +response);
 JSONArray feedJSONArray = new JSONArray("["+response+"]");
 for (int i = 0; i < feedJSONArray.length(); i++) {
     JSONObject jFeed = feedJSONArray.getJSONObject(i);
     Document document = Jsoup.parse(feedJSONArray.getString(i));
     Elements keywords = document.select("keywords");
     if (!keywords.isEmpty())
         String para = keywords.get(0).text().trim();
 }

TAG打印出来,但其他代码永远不会被执行

我尝试使用JSON但无济于事,我注意到代码的某些部分有纯HTML,JSOUP会起作用,问题是我如何循环返回的数组,甚至只是为了获得最基本的密钥,在这个护理中是id

2 个答案:

答案 0 :(得分:0)

返回数据的格式称为JSON,您可以使用Gson库在Android中解析它。您需要创建一个表示JSON的类,其对象将返回给您。 This是一个很好的网站,可以让你做到这一点。

答案 1 :(得分:0)

您提到的数据格式是&#34; JSON&#34;格式。所有json数据都将从大括号或方括号开始。 [和{之间的区别,方括号([)表示JSONArray节点的开头,而大括号({)表示JSONObject 。因此,在访问这些节点时,我们需要调用适当的方法来访问数据。

如果您的JSON节点以 [开头,那么我们应该使用 getJSONArray()方法。与节点以 {开头,然后我们应该使用 getJSONObject()方法相同。

一旦您对数据有了更好的理解,就很容易解析JSON。 我希望您正在寻找以下链接: http://www.androidhive.info/2012/01/android-json-parsing-tutorial/

希望它有所帮助!!