最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - An unexpected 'StartObject' node was found when reading from the JSON reader. A 'PrimitiveV

programmeradmin3浏览0评论

I'm using a rest API call to add an item to my 'Email' people picker column in a Sharepoint list. But I'm not able to add it due to this error.

I've tried keeping the payload without email but it still doesn't solve it

Code is self-explanatory but I will give you some insight if you want it

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 
},

I'm using a rest API call to add an item to my 'Email' people picker column in a Sharepoint list. But I'm not able to add it due to this error.

I've tried keeping the payload without email but it still doesn't solve it

Code is self-explanatory but I will give you some insight if you want it

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 
},
Share Improve this question asked Aug 17, 2019 at 7:12 xander cagexander cage 1772 gold badges3 silver badges12 bronze badges 4
  • Where exactly does the error occur? Why do you log data.d.result and then stringify result s? – baao Commented Aug 17, 2019 at 7:17
  • This is the error failure is {"readyState":4,"responseText":"{\"error\":{\"code\":\"-1, Microsoft.SharePoint.Client.InvalidClientQueryException\",\"message\":{\"lang\":\"en-US\",\"value\":\"An unexpected 'StartObject' node was found when reading from the JSON reader. A 'PrimitiveValue' node was expected.\"}}}","responseJSON":{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"An unexpected 'StartObject' node was found when reading from the JSON reader. A 'PrimitiveValue' node was expected."}}},"status":400,"statusText":"error"} – xander cage Commented Aug 17, 2019 at 7:31
  • I'm not able to post it – xander cage Commented Aug 17, 2019 at 7:33
  • Again, where does this error throw? In which line of your code. Maybe check if it works if you pass in a correct url instead of your function call as a string – baao Commented Aug 17, 2019 at 7:39
Add a ment  | 

1 Answer 1

Reset to default 3

The error should be json data format.

My test script based on your demo(Email people field allow multiple selections).

<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" />

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论