JQueryでJSONドキュメントを解析しようとしていますが、私のやり方はうまくいきません。アクセスしたいフィードは「http://marketplace.envato.com/api/edge/new-files-from-user:collins,themeforest.json」にあり、ここに戻り値があります:JQueryでJSONを解析するには
{
"new-files-from-user":[
{
"thumbnail":"http://3.s3.envato.com/files/60560.jpg",
"tags":"",
"user":"collis",
"url":"http://themeforest.net/item/manilla-photoshop-design/22803",
"live_preview_url":"http://2.s3.envato.com/files/60561/1_Home.__large_preview.jpg",
"uploaded_on":"Wed Dec 03 03:32:35 +1100 2008",
"cost":"10.00",
"item":"Manilla Photoshop Design",
"sales":"294",
"rating":"4",
"id":"22803"
},
{
"thumbnail":"http://2.s3.envato.com/files/60223.jpg",
"tags":"clean",
"user":"collis",
"url":"http://themeforest.net/item/black-white-simple-theme/22705",
"live_preview_url":"http://0.s3.envato.com/files/60224/1_home.__large_preview.jpg",
"uploaded_on":"Tue Dec 02 04:01:12 +1100 2008",
"cost":"8.00","item":"Black + White Simple Theme",
"sales":"272","
rating":"4",
"id":"22705"
},
{
"thumbnail":"http://1.s3.envato.com/files/44556.jpg",
"tags":"clean",
"user":"collis",
"url":"http://themeforest.net/item/quik-v1-admin-skin/17314",
"live_preview_url":"http://3.s3.envato.com/files/44557/1_green.__large_preview.jpg",
"uploaded_on":"Fri Sep 05 07:30:24 +1000 2008","cost":"12.00",
"item":"Quik v1 Admin Skin",
"sales":"336",
"rating":"5",
"id":"17314"
},
{"thumbnail":"http://3.s3.envato.com/files/45212.jpg",
"tags":"clean",
"user":"collis",
"url":"http://themeforest.net/item/freshcorp-business-template/17528",
"live_preview_url":"http://3.s3.envato.com/files/45213/1_Homepage.__large_preview.jpg",
"uploaded_on":"Tue Sep 09 06:10:50 +1000 2008",
"cost":"20.00",
"item":"FreshCorp - Business Template",
"sales":"277",
"rating":"4","id":"17528"
},
{"thumbnail":"http://0.s3.envato.com/files/45739.jpg",
"tags":"clean",
"user":"collis",
"url":"http://themeforest.net/item/real-estate-html-template/17732",
"live_preview_url":"http://0.s3.envato.com/files/45740/1_homepage.__large_preview.jpg",
"uploaded_on":"Fri Sep 12 14:22:45 +1000 2008",
"cost":"20.00","item":"Real Estate HTML Template",
"sales":"175",
"rating":"4",
"id":"17732"
}
]
}
テーブルを作成してJSONアイテムを追加するプレミデッドスクリプトが見つかりましたが(下)、実際には自分のdivをイメージとタイトルとリンクで作成していますアイテムに。私は無数のチュートリアルを試して、JQuery APIも読んでしまったので、うまく動作しないようです。誰でも助けてくれますか?右が不正なJavaScriptをある
<table id="userdata" border="1">
<thead>
<th>Thumbnail URL</th>
<th>Item URL</th>
<th>Cost</th>
<th>Number of Sales</th>
</thead>
<tbody>
</tbody>
</table>
<script>
$(document).ready(function(){
$.getJSON(
"http://marketplace.envato.com/api/edge/new-files-from-user:collins,themeforest.json",
function(data){
$.each(data.new-files-from-user, function(i,user){
var tblRow =
"<tr>"
+"<td>"+user.thumbnail+"</td>"
+"<td>"+user.url+"</td>"
+"<td>"+user.cost+"</td>"
+"<td>"+user.sales+"</td>"
+"</tr>"
$(tblRow).appendTo("#userdata tbody");
});
}
);
});
</script>
何が動作しませんか?どこが壊れているの? – hvgotcodes
あなたの質問は何ですか? – Hamish
どこが壊れているのか分かりません。私は 'new-files-from-user'プロパティに角括弧を追加しましたが、何も動作しません。私はJSONのフィードにアクセスしようとしていて、Themeforestの販売のために最後のアイテムを吐き出しています – Matt