Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 74020

Creating java variable from json file for offline use

$
0
0

I made offline web-app using html + JS and open it in browser. But making it offline make me can't open/read local file (.json) because CORS-error. So I read the file using :

<script> var jsonVar = "data/json/local_database.json"; </script> <~ loading data like this will cause CORS-error<script src="data/json/local_database.json"></script> <~ so read the file like this

and I want to make that file as variable, something like this :

<script> var jsonVar = local_database.json; </script>

Inside local_database.json is :

[
 {"no": 1,"nop": "\"55555\"","nama": "PT. YAMII","desa": "MYDESA","kecamatan": "MYCAMAT","status_terakhir": "Bangunan","pemilik_terakhir": "","keterangan": "Pabrik","luasan": 1161.925
 },
 {"no": 2,"nop": "\"44444\"","nama": "SAFIUDIN","desa": "DESAA","kecamatan": "CAMAAT","status_terakhir": "Rumah","pemilik_terakhir": "","keterangan": "","luasan": 3672.906
 }
 ]

The question is, how to do that?

My solution is to edit the .json file, and make the variable inside .json file, something like this :

var jsonVar = [
 {"no": 1,"nop": "\"55555\"","nama": "PT. YAMII","desa": "MYDESA","kecamatan": "MYCAMAT","status_terakhir": "Bangunan","pemilik_terakhir": "","keterangan": "Pabrik","luasan": 1161.925
 },
 {"no": 2,"nop": "\"44444\"","nama": "SAFIUDIN","desa": "DESAA","kecamatan": "CAMAAT","status_terakhir": "Rumah","pemilik_terakhir": "","keterangan": "","luasan": 3672.906
 }
 ];

Is there any other method to create variable from file directly without editing the .json file? because I have many .json to load and the .json file will be used for another purpose. Thank you.


Viewing all articles
Browse latest Browse all 74020

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>