parsing - Not able to parse JSON file in JavaScript -


i using javascript parse json file. not able understand error getting. please me on topic.

**my code: html file:

<title>json parser</title>  <script type="text/javascript">       function webglstart() {          var request = new xmlhttprequest();        request.open("get","test.json");        var my_json_object = json.parse(request.responsetext);      alert (my_json_object.result[0]);     }  </script>   </head>   <body onload="webglstart();">   </body>   </html>  

test.json file:

{"result": [0,1,2,3,4] } 

alert in above code not show on webpage.

it's straight forward jquery:

<script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript">       $.getjson('test.json', function(data) {              $.each(data, function(key, val) {         console.log("key=" + key + " " + "val=" + val);     }); }); 

for more sample code here: http://api.jquery.com/jquery.getjson/


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -