gpt4 book ai didi

javascript - 无法将 JSON 字符串转换为 javascript 对象

转载 作者:行者123 更新时间:2023-11-30 18:07:48 24 4
gpt4 key购买 nike

    var JSONObj='[{"rmaNumber":null,"orderReferenceNumber":"referene45","orderStatus":"Pending","dateRequested":null,"dateApproved":null,"segateAddress":null,"billingAddress":null,"shippingAddress":null,"returnForCredit":{"requested":null,"received":null,"shipped":35,"credited":45,"invoiceAmount":null},"returnForExchange":{"requested":null,"received":null,"shipped":35,"credited":45,"invoiceAmount":null},"totals":null}]'
var parsedJSON = eval('(\'+JSONObj+\')');
var result=parsedJSON.result;
var count=parsedJSON.count;
alert('result:'+result+' count:'+count);

提醒它给出 undefined :undefined

最佳答案

你应该使用 JSON.parse()为此:

var parsedJSON = JSON.parse(JSONObj);
console.log(parsedJSON[0].orderStatus); // "Pending"

注意:只有现代浏览器支持此方法。了解浏览器兼容性 here .

关于javascript - 无法将 JSON 字符串转换为 javascript 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15380152/

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