I'm new to JSON, WebDevelopment, Javascript ...
I have the 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 to read it using Javascript/Jquery and then display it. Later on I should develop code for Onclicking a "component A" on a webpage a list of components under it should be displayed and so on.Depending on the status variable a color is to be assigned to the component displayed ( in the form of an image like a box or something)
I wrote the 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 what are the javascript equivalent of java functions for JSON like getJSONArray(), getJSONObject() etc Secondly any suggestions as to how i go about printing the details using what API's etc.
jquery-1.9.1.min.js- is minimizedjquery-1.9.1.js, remove one of them from your file