gpt4 book ai didi

javascript - jQuery json解码

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:38:35 27 4
gpt4 key购买 nike

$.getJSON(
"test.php",
function(data){
... code should be here?
}
)

data 包含这段代码:

{
"name": "Mary",
"surname": "Carey"
}

我想创建这些变量:

theName = name from json;
theSurname = surname from json;

这个任务的真正语法是什么?

谢谢。

最佳答案

点符号:

theName = data.name;
theSurname = data.surname;

或方括号表示法:

theName = data['name'];
theSurname = data['surname'];

关于javascript - jQuery json解码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4877539/

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