function parseJson(file) { return new Promise( (resolve, reject) => { const reader = new FileReader(); reader.addEventListener(‘load‘, function(ev) { try { const obj = JSON.parse(ev.target.result); resolve(obj) } catch (error) { reject(error) } }) reader.readAsText(file) } ) } async function toParse(target) { const data = await parseJson(target.files[0]); console.log(data) }
原文:https://www.cnblogs.com/dhjy123/p/14769491.html