javascript - 将包含字符串数据的变量转换为 JavaScript REST API 的 JSON 对象

标签 javascript json rest sharepoint sharepoint-2013

这里我有名为 item 的变量并包含以下数据:

{
  __metadata: {
    "type": "SP.Data.ClinicalTestingPhaseIIListItem"
  },
  Control: 1,
  Randomization: 2,
  Blindings: 3,
  Groups: 4,
  DoseTitration: 5,
  Stratification: 6,
  PatientsDoseLevel: 7,
  TumourResponse: 8,
  DetermineWarrants: 9,
  Title: 1
}

现在,当我将它传递给下面编写的 ajax 调用时,经过一番研究后出现错误,我得到的结论是数据以字符串格式而不是对象传递。

Microsoft.SharePoint.Client.InvalidClientQueryException: A node of type PrimitiveValue was read from the JSON reader when trying to read the start of an entry. A StartObject node was expected.

下面是我的ajax调用

jQuery.ajax({
        url: requestUri,
        type: "POST",
        data: JSON.stringify(item),
        headers: header,
        success:function(){
        alert("List itme Inserted Sucessfully");    
        },
        error: function(data){
        console.log(data);
                alert(data.responseText);
        alert("Error Occured");
        }
});

最佳答案

删除 JSON.stringify 并查看

jQuery.ajax({

        url: requestUri,
        type: "POST",
        data: item,
        headers: header,
        success:function(){
        alert("List itme Inserted Sucessfully");    
        },
        error: function(data){
        console.log(data);
                alert(data.responseText);
        alert("Error Occured");
        }
});

关于javascript - 将包含字符串数据的变量转换为 JavaScript REST API 的 JSON 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24017053/

相关文章:

javascript - 获取 javascript 警报窗口中填充的 json 对象数据

javascript - 如何将 servlet 中的字符串解析为 javascript 并创建包含数组值的格式化对象

不使用 eval/new 函数的 JavaScript 模板库

JavaScript:onmouseout 事件在 onmouseover 后不起作用

javascript - 剧情 JS : hover event does not contain points

json - ResponseEntity 生成转义输出而不是 json

java - REST 服务没有响应

c# - 如何修复这个重定向循环?

html - html/css 中来自 JSON 对象的垂直排序输入

php - 在没有框架的情况下路由 REST 请求?