div中设置自定义属性存json数据就可以不用转义json里面的引号了,推荐使用encodeURIComponent编码json数据,防止json转换对象失败

在这里插入图片描述
图中leaderuserid属性存的是json编码后的数据

var arr=[{
    
    Key:1,Name:'物供'},{
    
    Key:2,Name:'欧阳修'}]; 

//对象转json字符串,然后转换为编码数据
var userJson = encodeURIComponent(JSON.stringify(arr));

//转换为对象,有效防止div自定义属性中存json有引号问题
var obj3=JSON.parse(decodeURIComponent(userJson));

猜你喜欢

转载自blog.csdn.net/u011511086/article/details/113313995