gpt4 book ai didi

json - 不使用 JSON.parse 获取 json 对象?

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

我发现了这个:

使用Python输出:

print ‘Content-type: text/x-json\n\n’
print json.dumps([{'title':arr['title']}])

并使用 Jquery 获取 json 字符串:

$ajax(   
success: function(msg){
if(msg[0].title) alert(msg[0].title);
}
)

可以,谁能告诉我这是为什么?谢谢~

最佳答案

如果 Content-Type 是 json,jQuery 会在现代浏览器内部调用 JSON.parse

        return window.JSON && window.JSON.parse ?
window.JSON.parse( data ) :
(new Function("return " + data))();

关于json - 不使用 JSON.parse 获取 json 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3800671/

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