gpt4 book ai didi

javascript - GSON 不是对象错误

转载 作者:行者123 更新时间:2023-12-02 18:17:58 24 4
gpt4 key购买 nike

我有以下 json 对象:

cNGJSON = {
"one": graph1.graphNode, "two": graph2.graphNode, "three": graph3.graphNode, "four": graph4.graphNode, "five": graph5.graphNode,"six": graph6.graphNode,
"seven": graph7.graphNode,"eight": graph8.graphNode, "nine": graph9.graphNode,"ten": graph10.graphNode, "eleven": graph11.graphNode, "twelve": graph12.graphNode,
"thirteen": graph13.graphNode,"fourteen": graph14.graphNode,"fifteen": graph15.graphNode,"sixteen": graph16.graphNode, "seventeen": graph17.graphNode, "eighteen": graph18.graphNode,
"nineteen": graph19.graphNode
};

其中graph1.graphNode是一个整数数组。

[1,2,3,4]

我使用 jQuery 将其发送到服务器:

  $.ajax({
url: 'validate',
type: 'post',
dataType: 'json',
success: function (data) {
console.log("Success!!");
},
data: cNGJSON
});

但是我得到了

Expected BEGIN_OBJECT but was STRING at line 1 column 1

每次尝试都会出错。

我尝试将 cNGJSON 设置为:

cNGJSON = { 
"one": "Number one", "two": "Number two"
};

我仍然遇到同样的错误。

最佳答案

As you want to send JSON object in your XHR request you need to stringify the JSON object first

$.ajax({
url: 'validate',
type: 'post',
dataType: 'json',
success: function (data) {
console.log("Success!!");
},
data: JSON.stringify(cNGJSON)
});

关于javascript - GSON 不是对象错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19099604/

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