gpt4 book ai didi

javascript - 如何在 json (javascript) 中使用变量作为对象

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

<分区>

var text = '{ "nusers" : [' +
'{ "firstName":"John" , "lastName":"Doe" },' +
'{ "firstName":"Anna" , "lastName":"Smith" },' +
'{ "firstName":"sadsf" , "lastName":"sdasda" },' +
'{ "firstName":"fnSaleh" , "lastName":"lnSaleh" }]}';

var va = "nuser";
obj = JSON.parse(text);

for(i=0;i< (obj.va.length);i++){

var st = obj.va.firstName;

console.log(st);
}

错误

“未捕获的类型错误:无法读取未定义的属性‘长度’”

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