为什么 'PrimitiveValue' 或 'StartObject' 节点是预期错误
why 'PrimitiveValue' or 'StartObject' node was expected error
我正在使用 SharePoint Online:
我有一个表单,其中有几个 select 选择字段。当我尝试添加项目时,出现以下错误:
"value: "A node of type 'StartArray' was read from the JSON reader when trying to read a value of a property; however, a 'PrimitiveValue' or 'StartObject' node was expected."
这里是多select的代码和字段。
$.ajax({
url: fullUrl,
method: "POST",
data: JSON.stringify({
'__metadata': { 'type': 'SP.Data.AuditItem' },
'Register': that.register,
'RiskRegister': that.nextIndex,
'Reopen': that.formatDate(that.reopen),
'RiskOrIssue': that.riskOrIssue,
'Locations': that.locations, //<---multi-select choice field
'ProblemT': that.probTitle,
'ProblemStatement': that.problemStatement,
'TaskOwner': that.taskOwner,
'RiskOwner': that.riskOwner,
'Auditor': that.auditor //<--- multi-select choice field
}),
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function(){
alert("Item Added!");
},
error: function(data){
console.log(data);
}
});
我该如何解决这个问题?
谢谢!
多select选择字段值需要用集合来设置,这里有一段代码供大家参考:
<script type="text/javascript">
var locations = ['Locations1','Locations3'];
var Auditors = ['Auditor1','Auditor3'];
var item = {
"__metadata": {
"type": 'SP.Data.MyListListItem'
},
"Title":'Test',
"Locations": { '__metadata': { 'type' : 'Collection(Edm.String)'}, results: locations },
"Auditor": { '__metadata': { 'type' : 'Collection(Edm.String)'}, results: Auditors }
};
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('MyList')/items",
method: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(item),
async: false,
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function(data) {
alert('The Request has been successfully Added');
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR.responseText);
alert('Error');
}
});
</script>
参考:
我正在使用 SharePoint Online:
我有一个表单,其中有几个 select 选择字段。当我尝试添加项目时,出现以下错误:
"value: "A node of type 'StartArray' was read from the JSON reader when trying to read a value of a property; however, a 'PrimitiveValue' or 'StartObject' node was expected."
这里是多select的代码和字段。
$.ajax({
url: fullUrl,
method: "POST",
data: JSON.stringify({
'__metadata': { 'type': 'SP.Data.AuditItem' },
'Register': that.register,
'RiskRegister': that.nextIndex,
'Reopen': that.formatDate(that.reopen),
'RiskOrIssue': that.riskOrIssue,
'Locations': that.locations, //<---multi-select choice field
'ProblemT': that.probTitle,
'ProblemStatement': that.problemStatement,
'TaskOwner': that.taskOwner,
'RiskOwner': that.riskOwner,
'Auditor': that.auditor //<--- multi-select choice field
}),
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function(){
alert("Item Added!");
},
error: function(data){
console.log(data);
}
});
我该如何解决这个问题?
谢谢!
多select选择字段值需要用集合来设置,这里有一段代码供大家参考:
<script type="text/javascript">
var locations = ['Locations1','Locations3'];
var Auditors = ['Auditor1','Auditor3'];
var item = {
"__metadata": {
"type": 'SP.Data.MyListListItem'
},
"Title":'Test',
"Locations": { '__metadata': { 'type' : 'Collection(Edm.String)'}, results: locations },
"Auditor": { '__metadata': { 'type' : 'Collection(Edm.String)'}, results: Auditors }
};
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('MyList')/items",
method: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(item),
async: false,
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function(data) {
alert('The Request has been successfully Added');
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR.responseText);
alert('Error');
}
});
</script>
参考: