0
私は以下のように有効なjsonpを持っています。私はそれを解析しようとしているが、私はどのようにビデオ要素にアクセスするのか分からない!いずれかは、どのようにループの内側にこれらの要素(ソース、親指、タイトル)を参照するように私に言うことができるのおかげjavascriptを使用して入れ子になったjsonpオブジェクトを解析する方法は?
有効JSONP:?
{
"categories": [{
"name": "october list",
"videos": [{
"sources": [
"http://www.somesite.com.com/test.m3u8"
],
"thumb": "http://www.somesite.com.com/1.jpg",
"title": "title of test",
"subtitle": "",
"description": ""
}, {
"sources": [
"http://www.somesite.com/test2.m3u8"
],
"thumb": "http://www.somesite.com/2.jpg",
"title": "test2",
"subtitle": "",
"description": ""
}
]
}]
}
のjavascript:
$.get("http://www.someapisite.com/test.php",
{
dataType: "jsonp"
},
function(data,status){
var json = $.parseJSON(data);
// then loop the single items
for(i in json)
{
// create HTML code
var div = "<div class=\"image\">\n" +
"<a href=\"javascript:dofunction('./test.php?title=" + json[i].title + "&TargetUrl=http://somesite.com/" + json[i].sources + "')\">\n" +
"<img src=\""+ json[i].thumb +"\" alt=\"..\" />\n" +
"</a>\n" +
"</div>\n";
// append it inside <body> tag.
$("#myDiv").append(div);
}
});
を使用して
。 – Bergi
'$ .parseJSON'を呼び出す必要はありません。 '$ .ajax' /' $ .get'/'$ .getJSON'はあなたのために既にそれを行います(実際のJSONPの場合、とにかく文字列を見ることはありません) – Bergi
[Access/process(nested)オブジェクト、配列またはJSON](http://stackoverflow.com/q/11922383/1048572)? – Bergi