其他分享
首页 > 其他分享> > eval转码字符串包裹的对象

eval转码字符串包裹的对象

作者:互联网

数据格式:

data: "{"sourceStatMap":{"face":18924,"car":0,"imsi":15754,"mac":3588952},"distinctSourceStatMap":{"face":2233,"car":0,"imsi":3758,"mac":32250},"distinctTodaySourceStatMap":{"face":0,"car":0,"imsi":0,"mac":0},"todaySourceStatMap":{"face":0,"car":0,"imsi":0,"mac":0}}"

需要将字符串对象解析出来

方法(使用 eval() 转换,需要在 json 字符外包裹一对小括号)

let obj = eval('(' + data + ')');

最终解析的结果:

{
    "sourceStatMap":{
        "face":18924,
        "car":0,
        "imsi":15754,
        "mac":3588952
    },
    "distinctSourceStatMap":{
        "face":2233,
        "car":0,
        "imsi":3758,
        "mac":32250
    },
    "distinctTodaySourceStatMap":{
        "face":0,
        "car":0,
        "imsi":0,
        "mac":0
    },
    "todaySourceStatMap":{
        "face":0,
        "car":0,
        "imsi":0,
        "mac":0
    }
}

 

标签:3758,转码,car,face,mac,eval,字符串,imsi
来源: https://www.cnblogs.com/rachelch/p/14904541.html