使用javascript创建json对象

潜孔

我已经使用Advanced Rest Client成功测试了我的REST服务,并在其中发送了如下所示的有效负载:

{
  "comments":"test comments",
  "internal_verification_areas":[
  {
     "area_id":"1",
     "selected":"1",
     "notes":"notes1",
     "status":"1"
  },
  {
     "area_id":"2",
     "selected":"0",
     "notes":"notes2",
     "status":"0"
  }]
}

如前所述,我的REST函数成功执行。

然后,我开始在Web界面上实现整个过程,并创建了internal_verification_areas对象,如下所示:

var verification_areas = {
        internal_verification_areas: [
            {
                area_id:"1",  // no need to quote variable names
                selected:"1",
                notes:"noter",
                status:"1"
            },
            {
                area_id:"2",  // no need to quote variable names
                selected:"1",
                notes:"noter2",
                status:"1"
            }
        ]
    };

然后将整个内容输入到我的请求中(注释参数是从textarea中获取的):

$.post("createInternalVerification.php",{comments: $('textarea#korrigeringer').val(),internal_verification_areas: verification_areas}

createInternalVerification.php将对数据进行json编码并请求服务。

问题是,我收到一条错误消息:“违反完整性约束:1048列'area_id'不能为空”。我认为发布的数据有问题,但是我不知道是什么。从我的POV中,我的Advanced Rest Client有效负载看起来类似于我从Web界面发送的有效负载。

编辑:

我注意到“网络”标签(谷歌浏览器)在有效负载方面显示出一些差异。我在响应中返回internal_verification_areas来分析差异。

(我的WEB接口接收){“错误”:false,“消息”:“实习生证明”,“测试”:{“ internal_verification_areas”:[{“ area_id”:“ 1”,“ selected”:“ 1”, “ notes”:“ noter”,“ status”:“ 1”},{“ area_id”:“ 2”,“ selected”:“ 1”,“ notes”:“ noter2”,“ status”:“ 1”} ,{“ area_id”:“ 3”,“ selected”:“ 1”,“ notes”:“ noter3”,“ status”:“ 1”}]}}

(高级的REST客户接收){“错误”:false,“消息”:“实习生准备工作”,“测试”:[{“ area_id”:“ 1”,“ selected”:“ 1”,“ notes”:” jAAAAAAA“,”状态“:” 1“,” id“:” 4“},{” area_id“:” 2“,”已选择“:” 0“,”注释“:” NEEEEEJ“,”状态“:” 0“,” id“:” 5“}]}

潜孔

猜猜我弄乱了对对象和数组的理解。原来我的Web界面正在发送和带有数组以及带有数组的对象。更改它(如本文后所示)解决了我的错误。很抱歉,瑟克姆斯浪费了您宝贵的时间,并给您独具技能的头脑带来极大的烦恼。我发现越来越令人恐惧的是,在这样的熟练和敬虔的人物面前出现有关StackOverflow的问题,这些人物不断提醒像我这样的奴才,Stackoverflow已成为傲慢开发人员的基石。

var internal_verification_areas = [
            {
                area_id:"1",  // no need to quote variable names
                selected:"1",
                notes:"noter",
                status:"1"
            },
            {
                area_id:"2",  // no need to quote variable names
                selected:"1",
                notes:"noter2",
                status:"1"
            },
            {
                area_id:"3",  // no need to quote variable names
                selected:"1",
                notes:"noter3",
                status:"1"
            }
        ];

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章