gpt4 book ai didi

javascript - 解析包含日期的 JSON 字符串时出现问题

转载 作者:行者123 更新时间:2023-12-03 07:12:26 25 4
gpt4 key购买 nike

我正在尝试将字符串解析为 json。我从服务器收到了字符串,但总是收到意外 token e 的错误

var data = JSON.parse(result)

结果是

{"success":true,"data":[{"carID":100110,"teamID":0,"carNO":"carNO1","simNO":"1212","machineNO":"800704","controlPassword":null,"machineType":null,"protocol":7,"routeway":0,"carType":null,"carBrand":null,"carColor":null,"installPlace":"7","installPerson":null,"businessPerson":null,"joinTime":new UtcDate(1460357844353),"overServiceTime":new UtcDate(1491840000000),"carRemark":null,"driver":null,"driverTel":null,"driverMobile":null,"driver2":null,"driver2Tel":null,"driver2Mobile":null,"password":null,"driverAddress":null,"driverFax":null,"driverCompany":null,"buyTime":null,"stoped":0,"specialRequest":"0","driverRemark":null,"regionAlarm":0,"regionID":0,"positionID":0,"notify":0,"notifyStart":new UtcDate(1460357844353),"notifyEnd":new UtcDate(1460357844353),"notifyText":null,"f_username":null,"isonline":0,"IfSendAlarmEmail":false,"AlarmEmail":null},{"carID":100111,"teamID":0,"carNO":"carNO2 TEst","simNO":"23","machineNO":"13000000005","controlPassword":null,"machineType":null,"protocol":7,"routeway":0,"carType":null,"carBrand":null,"carColor":null,"installPlace":"7","installPerson":null,"businessPerson":null,"joinTime":new UtcDate(1460358033120),"overServiceTime":new UtcDate(1491840000000),"carRemark":null,"driver":null,"driverTel":null,"driverMobile":null,"driver2":null,"driver2Tel":null,"driver2Mobile":null,"password":null,"driverAddress":null,"driverFax":null,"driverCompany":null,"buyTime":null,"stoped":0,"specialRequest":"0","driverRemark":null,"regionAlarm":0,"regionID":0,"positionID":0,"notify":0,"notifyStart":new UtcDate(1460358033120),"notifyEnd":new UtcDate(1460358033120),"notifyText":null,"f_username":null,"isonline":0,"IfSendAlarmEmail":false,"AlarmEmail":null}]}    

我已经在在线jsonparse上进行了测试http://json.parser.online.fr/

它也返回相同的错误。

如果我没记错的话,日期的格式是错误的,但我不允许接触服务器端。我做错了什么?

最佳答案

日期显然不是有效的 JSON。但如果您无权访问服务器,您可以使用正则表达式将这些日期转换为常规时间戳:

// Will convert   new UtcDate(1460357844353)      to      1460357844353
var data = JSON.parse( result.replace(/new UtcDate\(([0-9]+)\)/gi, "$1") );

JS Fiddle demo

关于javascript - 解析包含日期的 JSON 字符串时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36576054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com