我有像这样的JSON代码
[{"url":"http:\/\/mysite.xx\/img\/exart.JPG"},{"url":"http:\/\/mysite.xx\/img\/bost.png"},
{"url":"http:\/\/mysite.xx\/img\/03.png"},
{"url":"http:\/\/mysite.xx\/img\/04.png"},{"url":"http:\/\/mysite.xx\/img\/05.png"},
{"url":"http:\/\/mysite.xx\/img\/06.png"},{"url":"http:\/\/mysite.xx\/img\/07.png"},
{"url":"http:\/\/mysite.xx\/img\/08.png"},{"url":"http:\/\/mysite.xx\/img\/09.png"},
{"url":"http:\/\/mysite.xx\/img\/10.png"},{"url":"http:\/\/mysite.xx\/img\/11.png"},
{"url":"http:\/\/mysite.xx\/img\/12.png"},{"url":"http:\/\/mysite.xx\/img\/13.png"},
{"url":"http:\/\/mysite.xx\/img\/14.png"},{"url":"http:\/\/mysite.xx\/img\/15.png"},
{"url":"http:\/\/mysite.xx\/img\/16.png"},{"url":"http:\/\/mysite.xx\/img\/17.png"},
{"url":"http:\/\/mysite.xx\/img\/18.png"}]
我如何浏览所有线路?每个例子,当我去http://mysite.xx/my_post/#1时,我必须在我的JSON代码中看到第一个网址" http://mysite.xx/img/exart.JPG"在一个
答案 0 :(得分:4)
只需使用
$data = json_decode($data);
$url_5 = $data[5]['url']; // the value here is "http://mysite.xx/img/06.png"
它会为你提供带有' url'的哈希数组。键。 并随心所欲地做任何事情
答案 1 :(得分:0)
您可能想尝试一下。 https://stackoverflow.com/a/1637373/1042903
这个例子来自w3schools.com
<script>
var text = '{"employees":[' +
'{"firstName":"John","lastName":"Doe" },' +
'{"firstName":"Anna","lastName":"Smith" },' +
'{"firstName":"Peter","lastName":"Jones" }]}';
obj = JSON.parse(text);
document.getElementById("demo").innerHTML =
obj.employees[1].firstName + " " + obj.employees[1].lastName;
</script>
参考:http://www.w3schools.com/json/json_eval.asp
如果你愿意,你可以用这个关键字google,&#34; json解析循环javascript&#34;