console.log这样提示:
data: '{"site_name":"aaaa","site_keywords":"bbbb","site_beian":"闽ICP备8888888888号","site_description":"ccccc","site_statistic":"<a>wsdfadfasdfasdfasdfasdf</a>"}',
从mysql获取json数据,这碰到这个问题,前端怎么处理转换解析json类型?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
Convert String to JSON object :
用JSON.stringify()转换成字符串供后续使用。
尽量用 JSON.parse, eval 不推荐使用;
尽量加上try...catch,JSON 转对象出错几率蛮高的,例如有未转义字符、嵌套层数过多;
try{
} catch(e){
}
后端设置响应头的Content-Type为application/json,数据输出json格式的字符串,前端自动获得JSON对象,可以当js普通的object处理。