Access JSON elements using Javascript/Jquery -
i'm new json, webdevelopment, javascript ...
i have following json file
{ "component": "a", "status": 0, "children": [ { "component": "aa", "status": 0, "children": [ { "component": "aaa", "status": 0, "children": [] }, { "component": "aab", "status": 0, "children": [] } ] }, { "component": "ab", "status": 0, "children": [ { "component": "aba", "status": 0, "children": [] }, { "component": "abb", "status": 0, "children": [] } ] } ] }
i need read using javascript/jquery , display it. later on should develop code onclicking "component a" on webpage list of components under should displayed , on.depending on status variable color assigned component displayed ( in form of image box or something)
i wrote following code:
<html> <head> <title>demo</title> </head> <body> <script src="jquery-1.9.1.min.js"></script> <script src="jquery-1.9.1.js"></script> <script> $(document).ready(function() { var myitems; $.getjson('jsonfile.json', function(data) { jsonarray children = jsonfile.getjsonarray("children"); }); }); </script> </body> </html>
firstly javascript equivalent of java functions json getjsonarray(), getjsonobject() etc secondly suggestions how go printing details using api's etc.
please show syntax of $.each in context
var result = $('#result'); $.each(obj.children, function(i, v){ result.append('<div>' + + ' - ' + v.component + '</div>'); });
demo: http://jsfiddle.net/lbjbm/
documentation: jquery.each()
Comments
Post a Comment