【发布时间】:2017-08-29 21:00:01
【问题描述】:
我正在尝试使用 Web API 将实体添加到 Dynamics 2016 On Premise。该实体引用了其他三个实体。当我尝试发布实体时,我收到以下错误。
从 JSON 阅读器读取时发现意外的“StartArray”节点。需要一个“StartObject”节点。
此错误发生在我引用的三个实体上:ccseq_clientid、ccseq_employeeid、ccseq_setid。
这个错误是什么意思,我该如何解决?
变量
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;
}
【问题讨论】:
标签: javascript json ajax asp.net-web-api dynamics-crm