从 JSON reader 读取时发现意外的 'StartObject' 节点。需要一个 'PrimitiveValue' 节点
An unexpected 'StartObject' node was found when reading from the JSON reader. A 'PrimitiveValue' node was expected
我正在使用休息 API 调用将项目添加到 Sharepoint 列表中我的 'Email' 人员选择器列。但由于这个错误,我无法添加它。
我已经尝试过不使用电子邮件保留有效负载,但仍然无法解决问题
代码是不言自明的,但如果您需要,我会给您一些见解
setPeoplesColumn: function()
{
console.log("user id is "+addressBookListRestService.UserID);
var item=
{
"__metadata":
{
"type": 'SP.Data.Address_x0020_BookListItem'
},
"Title": 'Some Dude',
'EmailId' :
{
"results" : [_spPageContextInfo.userId]
}
};
$.ajax
({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Address Book')/items",
type: "POST",
headers:
{
"accept": addressBookListRestService.acceptHeaderValue,
"X-RequestDigest": addressBookListRestService.requestDigestHeaderValue,
"content-Type": addressBookListRestService.contentTypeHeaderValue
},
data: JSON.stringify(item),
success: function(data)
{
console.log("success is "+(data.d.result));
console.log("ID is "+JSON.stringify(data.d.results));
},
error: function(error) {
console.log("failure is "+JSON.stringify(error));
}
});//end of ajax function
},
错误应该是json数据格式。
我的测试脚本基于你的演示(电子邮件人员字段允许多项选择)。
<script type="text/javascript">
function setPeoplesColumn() {
console.log("user id is " + _spPageContextInfo.userId);
var item =
{
"__metadata":
{
"type": 'SP.Data.Address_x0020_BookListItem'
},
"Title": 'Some Dude',
'EmailId':
{
"results": [_spPageContextInfo.userId]
}
};
$.ajax
({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Address Book')/items",
type: "POST",
headers:
{
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
data: JSON.stringify(item),
success: function (data) {
console.log("success is " + (data.d));
console.log("ID is " + JSON.stringify(data.d));
},
error: function (error) {
console.log("failure is " + JSON.stringify(error));
}
});//end of ajax function
}
</script>
<input id="Button1" type="button" onclick="setPeoplesColumn()" value="button" />
我正在使用休息 API 调用将项目添加到 Sharepoint 列表中我的 'Email' 人员选择器列。但由于这个错误,我无法添加它。
我已经尝试过不使用电子邮件保留有效负载,但仍然无法解决问题
代码是不言自明的,但如果您需要,我会给您一些见解
setPeoplesColumn: function()
{
console.log("user id is "+addressBookListRestService.UserID);
var item=
{
"__metadata":
{
"type": 'SP.Data.Address_x0020_BookListItem'
},
"Title": 'Some Dude',
'EmailId' :
{
"results" : [_spPageContextInfo.userId]
}
};
$.ajax
({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Address Book')/items",
type: "POST",
headers:
{
"accept": addressBookListRestService.acceptHeaderValue,
"X-RequestDigest": addressBookListRestService.requestDigestHeaderValue,
"content-Type": addressBookListRestService.contentTypeHeaderValue
},
data: JSON.stringify(item),
success: function(data)
{
console.log("success is "+(data.d.result));
console.log("ID is "+JSON.stringify(data.d.results));
},
error: function(error) {
console.log("failure is "+JSON.stringify(error));
}
});//end of ajax function
},
错误应该是json数据格式。
我的测试脚本基于你的演示(电子邮件人员字段允许多项选择)。
<script type="text/javascript">
function setPeoplesColumn() {
console.log("user id is " + _spPageContextInfo.userId);
var item =
{
"__metadata":
{
"type": 'SP.Data.Address_x0020_BookListItem'
},
"Title": 'Some Dude',
'EmailId':
{
"results": [_spPageContextInfo.userId]
}
};
$.ajax
({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Address Book')/items",
type: "POST",
headers:
{
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
data: JSON.stringify(item),
success: function (data) {
console.log("success is " + (data.d));
console.log("ID is " + JSON.stringify(data.d));
},
error: function (error) {
console.log("failure is " + JSON.stringify(error));
}
});//end of ajax function
}
</script>
<input id="Button1" type="button" onclick="setPeoplesColumn()" value="button" />