gpt4 book ai didi

javascript - 如何在javascript中获取json键和值?

转载 作者:IT老高 更新时间:2023-10-28 12:43:20 28 4
gpt4 key购买 nike

我正在返回一个json,如下所示

{"name": "", "skills": "", "jobtitel": "Entwickler", "res_linkedin": "GwebSearch"}

我正在尝试获取每个元素的键和值:

..
}).done(function(data){
alert(data['jobtitel']);
});

我收到 undefined 警报。为什么?我试过 data.jobtitel,我试过循环但没有成功..

最佳答案

//By using jquery json parser    
var obj = $.parseJSON('{"name": "", "skills": "", "jobtitel": "Entwickler", "res_linkedin": "GwebSearch"}');
alert(obj['jobtitel']);

//By using javasript json parser
var t = JSON.parse('{"name": "", "skills": "", "jobtitel": "Entwickler", "res_linkedin": "GwebSearch"}');
alert(t['jobtitel'])

Check this jsfiddle

As of jQuery 3.0, $.parseJSON is deprecated. To parse JSON strings usethe native JSON.parse method instead.

Source: http://api.jquery.com/jquery.parsejson/

关于javascript - 如何在javascript中获取json键和值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18910939/

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