如何在具有键和值对的邮递员中将params作为json数组传递

时间:2016-02-05 12:29:14

标签: json postman

我无法使用键和值对传递postman中的json数组。 当像这样工作时使用

[
   {
     "serviceTypeId": 40,
     "serviceName": "standard Cut2",
     "active": true,
    },
    {
     "serviceTypeId": 44,
     "serviceName": "Special Cut1",
     "active": true,
    },
    {
     "serviceTypeId": 46,
     "serviceName": "Feather xxxy",
     "active": true,
    }
]

但是当我添加一个密钥时(即如下)

{"serviceType": [
        {
            "serviceTypeId": 40,
            "serviceName": "standard Cut2",
            "active": true,
        },
        {
            "serviceTypeId": 44,
            "serviceName": "Special Cut1",
            "active": true,
        },
        {
            "serviceTypeId": 46,
            "serviceName": "Feather xxxy",
            "active": true,
        }
    ]
}

1 个答案:

答案 0 :(得分:0)

您的Json格式不正确,活动属性后还有一个额外的逗号。去掉它。它应该是:

[  
   {  
      "serviceTypeId":40,
      "serviceName":"standard Cut2",
      "active":true
   },
   {  
      "serviceTypeId":44,
      "serviceName":"Special Cut1",
      "active":true
   },
   {  
      "serviceTypeId":46,
      "serviceName":"Feather xxxy",
      "active":true
   }
]

在数组中尝试:

{  
   "serviceType":[  
      {  
         "serviceTypeId":40,
         "serviceName":"standard Cut2",
         "active":true
      },
      {  
         "serviceTypeId":44,
         "serviceName":"Special Cut1",
         "active":true
      },
      {  
         "serviceTypeId":46,
         "serviceName":"Feather xxxy",
         "active":true
      }
   ]
}

如果您对自己的JSON不确定,可以使用互联网上的工具:https://jsonformatter.curiousconcept.com/

如果您的json是正确的,您将能够快速查看。