axios 读取本地json文件成功后,解析失败
export function getEmojiData() {
return axios({
method: 'get',
url: '/static/emojiDB.json',
responseType:'json',
// transformRequest: [function (data, headers) {
// // Do whatever you want to transform the data
// return JSON.stringify(data);
// }],
})
.then(function(res) {
return Promise.resolve(res.data);
});
}
调用时
getEmojiData().then((res)=>{
console.log(typeof res)
console.log(res);
console.log(JSON.parse(res))
})
在
JSON
数据中是仅允许"
(双引号),不允许'
(单引号)!报错信息也很明显,你把本地
json
文件中的所有单引号
替换成双引号
便可(注意是英文状态下)