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
    }
}

 

上一篇:[ATF]-ATF makefile的导读


下一篇:python eval函数