tazeha Posted July 17, 2015 Share Posted July 17, 2015 hello json data is array I want display mesghal values p,d,.... { "ati1": { "p": "8,935,000", "d": 0, "dp": 0, "dt": "", "h": "8,935,000", "l": "8,780,000", "t": "۲۵ تیر", "t-g": "16 July" }, "ati2": { "p": "8,665,000", "d": 0, "dp": 0, "dt": "", "h": "8,860,000", "l": "8,665,000", "t": "۲۵ تیر", "t-g": "16 July" }, "ati3": { "p": "8,720,000", "d": 0, "dp": 0, "dt": "", "h": "8,905,000", "l": "8,720,000", "t": "۲۵ تیر", "t-g": "16 July" }, "ati4": { "p": "8,840,000", "d": 0, "dp": 0, "dt": "", "h": "9,020,000", "l": "8,825,000", "t": "۲۵ تیر", "t-g": "16 July" }, "ons": { "p": "1,135.30", "d": "10.70", "dp": 0.94, "dt": "low", "h": "1,146.50", "l": "1,135.30", "t": "۱۸:۳۰", "t-g": "18:30" }, "mesghal": { "p": "3,889,000", "d": 0, "dp": 0, "dt": "", "h": "3,934,000", "l": "3,883,000", "t": "۲۵ تیر", "t-g": "16 July" }} <script type='text/javascript'> $(document).ready(function(){ $.getJSON('saipa.php', function(data) { console.log(data); $.each(data, function(key, val) { $('ul').append('<li id="shoker">' + val.p + ' ' + val.h + ' ' + val.t + ' ' + val.l + '</li>'); }); }); }); </script> but can't display pleas help Link to comment Share on other sites More sharing options...
justsomeguy Posted July 17, 2015 Share Posted July 17, 2015 That's an object, not an array. You can access data.mesghal. Link to comment Share on other sites More sharing options...
tazeha Posted July 18, 2015 Author Share Posted July 18, 2015 (edited) I write this but diplay undefined $(document).ready(function(){ $.getJSON('js.json', function(data) { $.each(data.mesghal, function() { $("ul").append("<li>Price:" + this['p'] +"</li><li>Date:" + this['p'] +"</li>"); }); }); }); results: Price:undefined Date:undefined Price:undefined Edited July 18, 2015 by tazeha Link to comment Share on other sites More sharing options...
justsomeguy Posted July 20, 2015 Share Posted July 20, 2015 Yes, you're still trying to loop through an object. Get rid of that loop, just access data.mesghal.p, data.mesghal.d, data.mesghal['t-g'], etc. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now