Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript创建json对象_Javascript_Jquery_Rest - Fatal编程技术网

使用javascript创建json对象

使用javascript创建json对象,javascript,jquery,rest,Javascript,Jquery,Rest,我已经使用Advanced REST Client成功地测试了我的REST服务,我正在发送一个如下所示的负载: { "comments":"test comments", "internal_verification_areas":[ { "area_id":"1", "selected":"1", "notes":"notes1", "status":"1" }, { "area_id":"2", "selecte

我已经使用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界面上实现整个过程,并创建了内部\u验证\u区域对象,如下所示:

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"
            }
        ]
    };
然后将整个内容输入到我的请求中,如下所示(comments参数从textarea获取):

createInternalVerification.php将json编码数据并请求服务

问题是,我得到一个错误:“完整性约束冲突:1048列‘area_id’不能为null”。我假设我发布的数据有问题,但我不知道是什么。从我的POV来看,我的高级Rest客户端负载与我从web界面发送的负载类似

编辑:

我注意到网络标签(google chrome)显示了我的有效负载的一些差异。我将在回复中返回内部验证区域,以分析差异

(我的WEB界面接收) {“error”:false,“message”:“Intern efrecropining opretet”,“test”:{“internal_-verification_-areads”:“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客户端接收)
{“error”:false,“message”:“Intern ef exploring opretet”,“test”:[{“area_id”:“1”,“selected”:“1”,“notes”:“1”,“notes”:“1”,“notes”:“jAAAAAAA”,“status”:“1”,“id”:“4”},{“area_id”:“2”,“selected”:“0”,“notes”:“neeeej”,“status”:“0”,“id”:“5”}

我想我对对象和数组的理解搞砸了。结果表明,我的web界面正在使用数组发送和数组以及使用数组发送对象。更改它(如本文后面所示)修复了我的错误。我很抱歉虫族浪费了你宝贵的时间,给你的unicum技术头脑带来了巨大的烦恼。我发现在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"
            }
        ];

在网络选项卡上检查您实际发送的内容-现在您的
内部\u验证\u区域
具有嵌套的
内部\u验证\u区域
@zerkms yes我在回复中返回我的对象。。你可以在我对这篇文章的编辑中看到不同之处。似乎Rest客户端在我的对象上没有“名称”。。不知道为什么您有两个嵌套的
内部\u验证\u区域
对象<代码>内部\u验证\u区域必须是一个数组,您将发送对象。hmm。。怎么样。我可以看到一个名为internal_verification_areas的变量,但不能看到两个对象。请详细说明:)您不能有json对象。你可以有一个包含json数据的字符串,也可以有一个对象。所以我帮助你成为了一名更好的开发人员:不仅你现在知道如何更好地调试,而且我还让你自己解决你的问题(这使你成为了一名更好的专家),现在你怪我?好吧,谢谢你说我无知。@zerkms:你一开始就给我指出了正确的方向,这是可以接受的,因为如果可能的话,我需要自己找到解决问题的办法。后来,你没有指出我在理解对象和数组的语法方面犯了什么错误,而是把重点放在我缺乏知识和你无法理解为什么我看不到我的语法中的差异这一事实上。我不认为一个人在没有投入足够的精力调试问题本身的情况下应该在这一页上要求解决方案。但我最近的经验是,这一页上对问题的评论越来越多地带有一种潜在的傲慢,这是因为其他人普遍缺乏技能,而不是干净的建设性对话。我关注的是缺乏关注,而不是知识。你只是没有足够仔细地比较两个对象。这种关注可以通过简单地让我意识到,我没有正确地构造有效载荷,并且强调有效载荷的区别来表达。不要强调为什么你不能理解,我看不出两者的区别。。我对你对我缺乏理解的个人感受不感兴趣,但有建设性的反馈让我理解。。。
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"
            }
        ];