gpt4 book ai didi

javascript - JSON.解析: why this doesn't work

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

我得到了一个 JSON :

$.ajax({
type: "POST",
url: myUrl,
success: function (result) {
var data = JSON.parse(result);
for (var i = 0; i < data.poles.length; i++) {
....

我在调试器中看到的是:

data = "{"poles":[{"id":36,"name":"AUVERGNE"},{"id":44,"name":"Alsace"},{"id":42,"name":"Artois"},....],"poleNumber":48}

但是我收到一条消息,说 data.poles 未定义

我想念什么?

最佳答案

Json还好吗?

{"poles":[{"id":36,"name":"AUVERGNE"},{"id":44,"name":"Alsace"},{"id":42,"name":"Artois"}],"poleNumber":48}

编辑:

好的,如果你有这个 JSON:

data = {"poles":[{"id":36,"name":"AUVERGNE"},{"id":44,"name":"Alsace"},{"id":42,"name":"Artois"}],"poleNumber":48}

你可以完美地制作data.poles。删除第一个“,你有一个错误的json,所以你永远不会解析

"{"poles":[{"id":36,"name":"AUVERGNE"},{"id":44,"name":"Alsace"},{"id":42,"name":"Artois"}],"poleNumber":48}

关于javascript - JSON.解析: why this doesn't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35800987/

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