0

I am looking for a way to parse a local JSON file from a none-hosted HTML page (e.g.: file:///C:/Folder/To/Your/HTML/default.html) without using AJAX since it will only entail an allow access-origin error. I also cannot use JSONP since the HTML is not hosted to any hosting server (whether locally or remotely hosted).

Jenny Casarino
  • 115
  • 1
  • 4

1 Answers1

0

suppose your json file 'json.data' is like below:

data = '[{"name" : "Harry", "age" : "32"}]';

you have to load the json file into html head section like below:

     <script type="text/javascript" src="file.json"></script>

and then in body section you have to call the javascript function to parse json data like..

<body onload="load();"></body>

javascript code:

<script>
function load() {
    var mydata = JSON.parse(data);
    alert(mydata[0].name);
    alert(mydata[0].age);
}
</script>

that's it.

user-4653387
  • 305
  • 1
  • 4
  • 17