3 回答

TA贡献1772条经验 获得超8个赞
从第一个花括号开始{,所有内容似乎都是JSON。
所以你可以使用之后获取字符串
let str = `1554710490545:[B@773c0cef:{"header":{"eventId":"c0afad22-6472-4f23-9a5d-1c5e0b48024e", "tmst":"1554710490545","agencyId":"tazz","customerId":"02c", "type":"EzNavigationHitPayload"},"trackingEzNavHit": {"hitBase":{"hitId":"8735b582-2be7-4764-ac83-da0e4d2206df", "ezakusBid":"a40afeb4-066f-4dc8-9de6-e450facecee9","tmst":"1554710490545", "wid":"widtest","cookieOk":true, "userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36","ipV4":"77.154.199.100","ezCustom": {"eznode":"gfnode-001","version":"4.0.10"},"agencyId":"tazz","customerId":"02c"}, "ezVarious":{"ignore":"STRING_TO_CHECK"}}}`;
let x = str.match(/({.*})/);
console.log(JSON.parse(x[1]).trackingEzNavHit)

TA贡献1827条经验 获得超4个赞
这是json数据。因此,您可以根据需要通过键访问值。例如,首先取空白json
let output={}
output["hintId"]= data.hintId
output["ezakusBid"] = data.ezakusBid
And you can create new json data as your wish

TA贡献1826条经验 获得超6个赞
如果您可以访问JSON,请使用它,而不是解析字符串...trackingEzNavHit.hitBase如果首键有时会不同,这是一种动态访问的方法。
const json = {
"1554710490545": {
"B@773c0cef": {
"header": {
"eventId": "c0afad22-6472-4f23-9a5d-1c5e0b48024e",
"tmst": "1554710490545",
"agencyId": "tazz",
"customerId": "02c",
"type": "EzNavigationHitPayload"
},
"trackingEzNavHit": {
"hitBase": {
"hitId": "8735b582-2be7-4764-ac83-da0e4d2206df",
"ezakusBid": "a40afeb4-066f-4dc8-9de6-e450facecee9",
"tmst": "1554710490545",
"wid": "widtest",
"cookieOk": true,
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36",
"ipV4": "77.154.199.100",
"ezCustom": {
"eznode": "gfnode-001",
"version": "4.0.10"
},
"agencyId": "tazz",
"customerId": "02c"
},
"ezVarious": {
"ignore":"STRING_TO_CHECK"
}
}
}
}
};
console.log(json[Object.keys(json)[0]][Object.keys(json[Object.keys(json)[0]])].trackingEzNavHit.hitBase);
添加回答
举报