gpt4 book ai didi

json - Angular 的 $http.get 期望 JSON 使用什么语法?

转载 作者:可可西里 更新时间:2023-11-01 15:27:43 25 4
gpt4 key购买 nike

我的 JSON:

[
{"animal":"dog", "isCute":"true"},
{"animal":"worm", "isCute":"false"},
]

当我使用提供此 JSON 的 URL 调用 $http.get() 时,出现以下错误。是我的 JSON 格式不正确,还是我做错了什么?

SyntaxError: Unexpected token ]
at Object.parse (native)
at Ib (angular.min.js:13:504)
at e.defaults.transformResponse (angular.min.js:59:501)
at angular.min.js:59:262
at Array.forEach (native)
at q (angular.min.js:7:264)
at ac (angular.min.js:59:244)
at c (angular.min.js:60:458)
at r (angular.min.js:96:280)
at angular.min.js:97:417

最佳答案

第二个对象后有一个逗号,请将其删除:

[
{"animal":"dog", "isCute":"true"},
{"animal":"worm", "isCute":"false"}
]

我找到了 JSONLint在诊断像您这样的 JSON 问题时提供帮助。

关于json - Angular 的 $http.get 期望 JSON 使用什么语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23377352/

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