简体   繁体   中英

How to parse JSON file using Javascript

I want to read a JSON file that in my local machinge using Javescript, and parse it to a Javascript object such as this code:

var parsed = JSON.parse(JSON_file);

Is it possible to read the file from the disk? Or there is other methods to do that. Thanks.

Here is a nice tutorial on how you can do it using HTML5's FileReader API, but there is one constraint: you can only interact with a file selected by the user via a file input field.

http://www.html5rocks.com/en/tutorials/file/dndfiles/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM