简体   繁体   English

Sharepoint 2013 Rest API:创建到多值列

[英]Sharepoint 2013 Rest API: create to multivalue column

I'm trying to save some values to a multi value field, more precisely a survey list column. 我正在尝试将一些值保存到多值字段,更确切地说是调查列表列。 My attempts: 我的尝试:

$.ajax({
   url: "somesitecollection/_api/web/lists/getByTitle('survey')/items",
   type: "POST",
   contentType: "application/json;odata=verbose",
   data: JSON.stringify({
       '__metadata': {
           'type': 'SP.Data.SurveyListItem'
       },
       'Question1': {
           "__metadata": {
               "type": "Collection(SP.FieldRatingScaleQuestionAnswer)"
           },
           "results": [2, 3, 5]
       },
       'Comment': "Thanks for..."
   }),
   headers: {
       "accept": "application/json;odata=verbose",
       "X-RequestDigest": $("#__REQUESTDIGEST").val()
   },

   success: function (data) {
       console.log("done");
   },
   error: function (err) {
       console.log(err.status + " - " + err.responseJSON.error.message.value);
   }
});

I think there's something wrong with the "results" part in the "Question1" JSON, don't really find the problem though. 我认为“ Question1” JSON中的“结果”部分出了问题,但实际上并没有发现问题。

Error message: 错误信息:

"400: An unexpected 'PrimitiveValue' node was found when reading from the JSON reader. A 'StartObject' node was expected." “ 400:从JSON读取器读取时,发现意外的'PrimitiveValue'节点。应为'StartObject'节点。”

What does that mean? 这意味着什么?

Update 更新

Tried with this code: 尝试使用此代码:

$.ajax({
url: "somesitecollection/_api/web/lists/getByTitle('survey')/items",
   type: "POST",
   contentType: "application/json;odata=verbose",
   data: JSON.stringify({
       '__metadata': {
           'type': 'SP.Data.SurveyListItem'
       },
       'Question1': {
        "__metadata": {
            "type": "Collection(SP.FieldRatingScaleQuestionAnswer)"
        },
        "results": [
            {
                "Answer": 1
            }, {
                "Answer": 5
            }, {
                "Answer": 4
            }
        ]
    },
    'Comment': "Thanks for..."
}),
headers: {
    "accept": "application/json;odata=verbose",
    "X-RequestDigest": $("#__REQUESTDIGEST").val(),
},

success: function (data) {
    console.log("ok");
},
error: function (err) {
    console.log(err.status + " - " + err.responseJSON.error.message.value);
}
});

No errors now. 现在没有错误。 Only the comment is saved though. 但是,仅保存注释。 Any idea? 任何想法?

A while after posting I found the solution. 发布一段时间后,我找到了解决方案。 You have to give the question too: 您也必须提出一个问题:

"results": [
   {
      "Answer": 1,
      "Question": "Question 1"
   }, {
      "Answer": 5,
      "Question": "Question 2"
   }, {
      "Answer": 4,
      "Question": "Question 3"
   }
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SharePoint 2013:REST API,GET JSON,显示列表项 - SharePoint 2013: REST API, GET JSON, Display List Items 获得400个错误请求SharePoint 2013 Rest API - Getting 400 Bad Request SharePoint 2013 Rest API SharePoint 2013中的托管元数据列 - Managed metadata column in SharePoint 2013 每次尝试将变量设置为返回值时,SharePoint 2013 REST API 查询都会引发错误 - SharePoint 2013 REST API Query Throws an Error Every Time I Try to Set a Variable to a Returned Value 如何在SharePoint REST API中获取列表列的类型 - How to get the type of a List Column in SharePoint REST API 使用jQuery(REST API)和CSOM(ECMASCRIPT)的SharePoint 2013 Property Bag CRUD - SharePoint 2013 Property Bag CRUD using jQuery (REST API) and CSOM (ECMASCRIPT) 如何在SharePoint 2013中使用REST API + JQuery访问文档的URL? - How to access a doc's URL using REST API + JQuery in SharePoint 2013? 使用REST API在线获取SharePoint 2013中包含附件和其他字段数据的列表数据 - Get the List data including attachments and other fields data in SharePoint 2013 online using REST API 如何使用 Sharepoint Rest API 在列表列上实现 LIKE(filter)? - How to implement LIKE(filter) on a list column using Sharepoint Rest API? 无法在Sharepoint 2013列表中创建新项目 - Unable to create new item in Sharepoint 2013 List
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM