gpt4 book ai didi

javascript - 如何解决错误 : An unexpected 'StartArray' node was found when reading from the JSON reader. 预期为 'StartObject' 节点。?

转载 作者:行者123 更新时间:2023-12-03 10:03:41 29 4
gpt4 key购买 nike

我正在尝试使用 Web API 将实体添加到 Dynamics 2016 On Premise。该实体引用了其他三个实体。当我尝试发布实体时,我收到以下错误。

An unexpected 'StartArray' node was found when reading from the JSON reader. A 'StartObject' node was expected.

此错误发生在我引用的三个实体上:ccseq_clientid、ccseq_employeeid、ccseq_setid。

我看过 this问题和 this问题,但没有成功。

这个错误是什么意思,我该如何解决?

变量

public contentType: string = "application/json;";
public dataType: string = "json";
public expenseTransaction: string = this.connection + "ccseq_expensetransactions";
public expenseTransactionSet: string = this.connection + "ccseq_expensetransactionsets";
public client: string = this.connection + "ccseq_clients";
public systemUser: string = this.connection + "systemusers";

Ajax 调用

Create(expenses: Array<ExpenseTransactionBase>): void {
for (let i: number = 0; i < expenses.length; i++) {
$.ajax({
url: this.expenseTransaction,
type: "POST",
contentType: this.contentType,
accepts: this.contentType,
dataType: this.dataType,
data: JSON.stringify(expenses[i].toJSON()),
success: function (data: any): void {
alert("Success");
},
error: function (data: any) {
alert("error");
}
});
}
};

JSON 创建

toJSON(): any[] {
let json = [];
json[0] = {
"ccseq_clientid@odata.bind": this.client + "(" + this.ccseq_clientid + ")",
"ccseq_clientnumber": this.ccseq_clientnumber,
"ccseq_employeefirstname": this.ccseq_employeefirstname,
"ccseq_employeelastname": this.ccseq_employeelastname,
"ccseq_employeeid@odata.bind": this.systemUser + "(" + this.ccseq_employeeid + ")",
"ccseq_expenseerrorcode": this.ccseq_expenseerrorcode,
"ccseq_generalledgername": this.ccseq_generalledgername,
"ccseq_generalledgernumber": this.ccseq_generalledgernumber,
"ccseq_groupcode": this.ccseq_groupcode,
"ccseq_mastercardposteddate": this.ccseq_mastercardposteddate,
"ccseq_mastercardtransactiondate": this.ccseq_mastercardtransactiondate,
"ccseq_mastercardtransactionparentcompany": this.ccseq_mastercardtransactionparentcompany,
"ccseq_navcompanycode": this.ccseq_navcompanycode,
"ccseq_navemployeeid": this.ccseq_navemployeeid,
"ccseq_navgeographycode": this.ccseq_navgeographycode,
"ccseq_navjobclasscode": this.ccseq_navjobclasscode,
"ccseq_navservicecode": this.ccseq_navservicecode,
"ccseq_setid@odata.bind": this.expenseTransactionSet + "(" + this.ccseq_setid + ")",
"ccseq_transactionamount": this.ccseq_transactionamount,
"ccseq_transactiondate": this.ccseq_transactiondate,
"ccseq_transactiondescription": this.ccseq_transactiondescription,
"ccseq_transactiontype": this.ccseq_transactiontype,
"ccseq_vendor": this.ccseq_vendor,
"statecode": this.statecode
};

return json;
}

最佳答案

如错误中所述,您应该发布一个 JSON 对象,而不是一个数组。

我相信你需要的改变就是改变:

toJSON(): any[] {
let json = [];
json[0] = {
//...

toJSON(): any[] {
let json = {
//...

关于javascript - 如何解决错误 : An unexpected 'StartArray' node was found when reading from the JSON reader. 预期为 'StartObject' 节点。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43210979/

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