How can I serialize an input File object to JSON?

后端 未结 6 1710
粉色の甜心
粉色の甜心 2021-01-14 04:12

I want to convert an HTML input file to a JSON string like this:

var jsonString = JSON.stringify(file);
console.log( file );
console.log( jsonString );
         


        
6条回答
  •  醉梦人生
    2021-01-14 04:46

    When you pass a json string Javascript internally trnsform it to Json object and hence no need to parse it.

    follow steps in case of of json file ->

    $('#inp_import_template')[0].files[0]
    

    Now your json file is transformed to json object (Javascript).

提交回复
热议问题