2016-04-11 2 views
0

Wie kann ich eine Schleife einfügen und für eine oder mehrere jpg screenshot-urls von json-variable "screenshotUrls" anzeigen?Ausgabe von mehr als einem Screenshots aus JSON-Datei (z. B. Itunes Search API)?

$.getJSON("https://itunes.apple.com/lookup?id=343200656&callback=?", function (data) { 
 
var icon = \t \t document.getElementById("icon"); 
 
var name = \t \t document.getElementById("name"); 
 
var description = \t document.getElementById("description"); 
 

 
icon.src = \t \t data.results[0].artworkUrl100; 
 
name.innerHTML = \t data.results[0].trackName; 
 
description.innerHTML = \t data.results[0].description; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="appicon"><img id="icon"></div> 
 
<h3 id="name">.</h3> 
 
<p id="description">.</p>

+0

Bevor Sie sich mit dem Problem beschäftigen, warum haben Sie diesen Post IOS markiert? Gibt es etwas bestimmtes IOS darüber? (Sie sollten es auch JQUERY markieren.) –

Antwort

0

Als ich nenne das URL (https://itunes.apple.com/lookup?id=343200656&callback= < -?. Stellen Sie sicher, dass kopieren auch becuase SO es aus dem Hyperlink entfernt, wahrscheinlich weil sie ungültig ist, aber es ist im Preis inbegriffen in der ursprünglichen URL im Skript ...), das ist die Antwort:

{ 
"errorMessage":"Invalid value(s) for key(s): [callback]", 
"queryParameters":{"output":"json", "callback":"A javascript function to handle your search results", "country":"ISO-2A country code", "limit":"The number of search results to return", "term":"A search string", "lang":"ISO-2A language code"} 
} 

Wenn ich Sie wäre, ich es anfangen würde, bevor der Suche mehr weiter.

In der Zwischenzeit (Wir haben eine kleine Diskussion über die abschließende? Nach dem Rückruf =? In der ursprünglichen URL. Das gibt einen Fehler für mich). Ich benutze den ohne den letzten? in der URL. (Es ist auch ungültig, zwei in die URL zu setzen)

Wie die Antwort verwenden?

Symply etwas tun, wie folgt aus:

var myResp = data; 

Nächste Verwendung myResp als ein Objekt mit Eigenschaften (Name/Wert paisr)

Zum Beispiel:

myResp.resultCount <-- will return 1 

Die Antwort sieht aus wie das folgende zu mir:

{ 
"resultCount":1, 
"results": [ 
{ 
"screenshotUrls":["http://a4.mzstatic.com/us/r30/Purple5/v4/37/00/46/37004662-657e-1964-a0dd-1266ddf6e096/screen320x320.jpeg", "http://a4.mzstatic.com/us/r30/Purple69/v4/49/16/ba/4916ba99-3c0f-1b18-b873-a509e8b7a5e3/screen320x320.jpeg", "http://a2.mzstatic.com/us/r30/Purple7/v4/4e/0b/56/4e0b56da-8dcd-8be2-d07a-64631ff45295/screen320x320.jpeg", "http://a4.mzstatic.com/us/r30/Purple7/v4/e6/16/94/e6169414-818b-a86c-f37c-4bad6a9f1f6f/screen320x320.jpeg", "http://a1.mzstatic.com/us/r30/Purple69/v4/9b/a1/6f/9ba16f4f-99bd-36a2-fccd-c3edfa181ff3/screen320x320.jpeg"], "ipadScreenshotUrls":[], "artworkUrl512":"http://is3.mzstatic.com/image/thumb/Purple5/v4/80/28/4c/80284c71-3c6b-470c-00a3-b7129e4ab814/source/512x512bb.jpg", "artistViewUrl":"https://itunes.apple.com/us/developer/rovio-entertainment-ltd/id298910979?uo=4", "artworkUrl60":"http://is3.mzstatic.com/image/thumb/Purple5/v4/80/28/4c/80284c71-3c6b-470c-00a3-b7129e4ab814/source/60x60bb.jpg", "artworkUrl100":"http://is3.mzstatic.com/image/thumb/Purple5/v4/80/28/4c/80284c71-3c6b-470c-00a3-b7129e4ab814/source/100x100bb.jpg", "isGameCenterEnabled":true, "kind":"software", "features":["gameCenter"], 
"supportedDevices":["iPhone-3GS", "iPhone4", "iPodTouchFourthGen", "iPad2Wifi", "iPad23G", "iPhone4S", "iPadThirdGen", "iPadThirdGen4G", "iPhone5", "iPodTouchFifthGen", "iPadFourthGen", "iPadFourthGen4G", "iPadMini", "iPadMini4G", "iPhone5c", "iPhone5s", "iPhone6", "iPhone6Plus", "iPodTouchSixthGen"], "advisories":[], "languageCodesISO2A":["EN", "FR", "DE", "IT", "JA", "PT", "RU", "ZH", "ES", "ZH"], "fileSizeBytes":"71674372", "sellerUrl":"http://www.angrybirds.com/", "averageUserRatingForCurrentVersion":4.0, "userRatingCountForCurrentVersion":1195, "trackContentRating":"4+", "trackCensoredName":"Angry Birds", "trackViewUrl":"https://itunes.apple.com/us/app/angry-birds/id343200656?mt=8&uo=4", "contentAdvisoryRating":"4+", "minimumOsVersion":"6.0", "formattedPrice":"$0.99", "currency":"USD", "wrapperType":"software", "version":"6.0.1", "artistId":298910979, "artistName":"Rovio Entertainment Ltd", "genres":["Games", "Arcade", "Entertainment", "Action"], "price":0.99, 
"description":"Use the unique powers of the Angry Birds to destroy the greedy pigs' defenses!\u2028\u2028\n\nThe survival of the Angry Birds is at stake. Dish out revenge on the greedy pigs who stole their eggs. Use the unique powers of each bird to destroy the pigs’ defenses. Angry Birds features challenging physics-based gameplay and hours of replay value. Each level requires logic, skill and force to solve.\u2028\u2028\n\nIf you get stuck in the game, you can purchase the Mighty Eagle! Mighty Eagle is a one-time in-app purchase in Angry Birds that gives unlimited use. This phenomenal creature will soar from the skies to wreak havoc and smash the pesky pigs into oblivion. There’s just one catch: you can only use the aid of Mighty Eagle to pass a level once per hour. Mighty Eagle also includes all new gameplay goals and achievements!\u2028\u2028\n\nIn addition to the Mighty Eagle, Angry Birds now has power-ups! Boost your birds’ abilities and three-star levels to unlock secret content! Angry Birds now has the following amazing power-ups: Sling Scope for laser targeting, King Sling for maximum flinging power, Super Seeds to supersize your birds, and Birdquake to shake pigs’ defenses to the ground!\u2028\u2028\n\nHAVING TROUBLE? Head over to https://support.rovio.com where you can browse FAQs or submit a request to our support flock!\n\n#1 IPHONE PAID APP in US, UK, Canada, Italy, Germany, Russia, Sweden, Denmark, Finland, Singapore, Poland, France, Netherlands, Malta, Greece, Austria, Australia, Turkey, UAE, Saudi Arabia, Israel, Belgium, Norway, Hungary, Malaysia, Luxembourg, Portugal, Czech Republic, Spain, Ireland, Romania, New Zealand, Latvia, Lithuania, Estonia, Nicaragua, Kazakhstan, Argentina, Bulgaria, Slovakia, Slovenia, Mauritius, Chile, Hong Kong, Pakistan, Taiwan, Colombia, Indonesia, Thailand, India, Kenya, Macedonia, Croatia, Macau, Paraguay, Peru, Armenia, Philippines, Vietnam, Jordan and Kuwait. \u2028\u2028\n\n#1 IPHONE PAID GAME in more countries than we can count!\n\nTerms of Use: http://www.rovio.com/eula\u2028\nPrivacy Policy: http://www.rovio.com/privacy\u2028\n\nThis application may require internet connectivity and subsequent data transfer charges may apply.\n\n\nImportant Message for Parents\n\nThis game may include:\n- Direct links to social networking websites that are intended for an audience over the age of 13.\n- Direct links to the internet that can take players away from the game with the potential to browse any web page.\n- Advertising of Rovio products and also products from select partners.\n- The option to make in-app purchases. The bill payer should always be consulted beforehand.", "trackName":"Angry Birds", "trackId":343200656, "bundleId":"com.clickgamer.AngryBirds", "releaseDate":"2009-12-11T08:00:00Z", "primaryGenreName":"Games", "isVppDeviceBasedLicensingEnabled":true, "currentVersionReleaseDate":"2015-12-11T08:02:04Z", "releaseNotes":"The #1 App of all time turns 6!\nJoin the celebration in 15 all-new levels in the BirdDay episode!", "sellerName":"Rovio Entertainment Ltd", "primaryGenreId":6014, "genreIds":["6014", "7003", "6016", "7001"], "averageUserRating":4.5, "userRatingCount":822974}] 
} 

Nun, wie möchten Sie fortfahren?

EDIT: Sie wollen alle Screenshot URL.

können Sie gehen dort mit so etwas wie:

myResp.results[0].screenshotUrls <-- will be an array. 

Ich habe den Code nicht überprüft, sondern nur die JSON-Antwort untersuchen und versuchen, das gewünschte Element zu gehen, die Aufmerksamkeit auf die Verrücktheit des Einzahlers Antwort, das ist eine Mischung aus Objekt- und Array-Notation.

+0

das Skript funktioniert für mich, keine Fehler (auch im Snippet-Browser). Ich möchte nur wissen, wie ich eine Schleife für die Screenshots einfügen kann. Danke! – decibel

+0

Wenn Sie https://itunes.apple.com/lookup?id=343200656&callback= eingeben? Erhalten Sie in Ihrem Browser eine gültige JSON-Antwort? –

+0

Ja, ich bekomme eine schöne gültige JSON-Datei (RFC 4627) !? – decibel

Verwandte Themen