gpt4 book ai didi

Javascript 数据格式,这是 JSON 吗?

转载 作者:行者123 更新时间:2023-11-29 17:29:01 25 4
gpt4 key购买 nike

我使用的一些 jquery 插件需要这种格式的数据作为其输入类型

[
{image : '1.jpg', title : 'Title', url : '', age : 24, location : 'US', name : 'John', description : 'Long Text'},
{image : '1.jpg', title : 'Title', url : '', age : 24, location : 'US', name : 'John', description : 'Long Text'},
{image : '1.jpg', title : 'Title', url : '', age : 24, location : 'US', name : 'John', description : 'Long Text'}
]

我的问题是,这种数据是什么以及如何创建它?这还是 JSON 吗?因为当我尝试用 PHP 传递 json_encoded 数组并用 jquery 获取它时,我得到了这种格式:

[
{'image' : '1.jpg', 'title' : 'Title', 'url' : '', 'age' : 24, 'location' : 'US', 'name' : 'John', 'description' : 'Long Text'},
{'image' : '1.jpg', 'title' : 'Title', 'url' : '', 'age' : 24, 'location' : 'US', 'name' : 'John', 'description' : 'Long Text'},
{'image' : '1.jpg', 'title' : 'Title', 'url' : '', 'age' : 24, 'location' : 'US', 'name' : 'John', 'description' : 'Long Text'}
]

注意变量名的引号。这使得代码无法正常工作。

最佳答案

第一个是 JavaScript 数组文字,其中包含对象文字它是 not JSON .

第二个也是包含对象的数组文字。它更接近 JSON ,但不是 100% 有效,因为 JSON 要求所有字符串都用双引号引起来。例如,这是有效的 JSON:

[{"image": "1.jpg", "title": "Title" }]

如果您不确定您正在查看的 JSON 是否有效,您可以随时通过 JSONLint 运行它并亲自看看。

关于Javascript 数据格式,这是 JSON 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6171767/

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