如何使用 jQuery 读取以下深层嵌套的 json 文件?
{
"frames": {
"a1-0.png":
{
"frame": {"x":24,"y":20,"w":12,"h":12},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":50,"y":152,"w":12,"h":12},
"sourceSize": {"w":256,"h":192}
},
"a1-1.png":
{
"frame": {"x":0,"y":194,"w":32,"h":44},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":39,"y":121,"w":32,"h":44},
"sourceSize": {"w":256,"h":192}
},
"a1-2.png":
{
"frame": {"x":400,"y":194,"w":60,"h":112},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":60,"y":51,"w":60,"h":112},
"sourceSize": {"w":256,"h":192}
}
}
}
以下几行 jQuery 代码我用来阅读这个。但它不起作用。有人可以帮助我如何阅读所有这些元素吗?
此处“ a1-0.png ”无法更改,因为精灵表中有 400 多张图像。这个 json 文件代表了那个精灵表。这是使用名为texture-packer的软件制作的。
jQuery代码在这里:
<button id="FrameNumber">Frame Number</button>
<div id="results"></div>
<script>
$(document).ready(function(e) {
var url="sprite/bounce.json";
$("#FrameNumber").click(function(){
$.getJSON(url,function(result){
$("#results").append('<p>'+result+'</p>');
});
});
});
</script>