weixin_33716941 2017-07-25 17:57 采纳率: 0%
浏览 24

硬json拉值

My json has structure:

{"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"}},...}

I try tu pull the values like 'znizka' and 'autor', with to loops, no succes. I dont know if it concernes JSON.stringify which I dont have in code(I dont know how to put it in $.getJSON) or it is simply the strange format of json. Thank you for help!

$.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条回答 默认 最新

  • weixin_33727510 2017-07-25 18:07
    关注

    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);
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

    </div>
    
    评论

报告相同问题?