硬json拉取价值

时间:2017-07-25 17:57:09

标签: jquery json ajax

我的json有结构:

{"0":{"pozycja":0,"znizka":{"0":"0.00"},"autor":{"0":"Cream Software"}},"1":{"pozycja":1,"znizka":{"0":"0.00"},"autor":{"0":"Cream Software"}},"2":{"pozycja":2,"znizka":{"0":"0.00"},"autor":{"0":"Cream Software"}},...}

我试着把'znizka'和'autor'这样的值拉到循环中,没有成功。我不知道它是否涉及我在代码中没有的JSON.stringify(我不知道如何将它放在$ .getJSON中)或者它只是json的奇怪格式。谢谢你的帮助!

$.getJSON("./baza.json", function(data){
console.log(data);
console.log(data.length);
for (var i = 0; i < data.length; i ++ ){
       $.each(data[i], function(index, items) {
           var pozycja = items.pozycja;
           var znizka = items.znizka;
           $('.list').append('<li>' + pozycja + '</li>' + '<li>' + znizka + '</li>');
       });
   }

});

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
var json={"0":{"pozycja":0,"znizka":{"0":"0.00"},"autor":{"0":"Cream Software"}},"1":{"pozycja":1,"znizka":{"0":"0.00"},"autor":{"0":"Cream Software"}},"2":{"pozycja":2,"znizka":{"0":"0.00"},"autor":{"0":"Cream Software"}}};
var obj=jQuery.parseJSON(JSON.stringify(json));
$.each(obj,function(key,value){
   console.log(value.pozycja);
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;
&#13;
&#13;