首页 > 解决方案 > 如何在 HTTP 请求的 JSON 正文中传递 JSON 字符串?

问题描述

如何在 HTTP 请求的 JSON 正文中传递 JSON 字符串?ServiceNow 将请求发送到 Azure Devops 以设置管道变量的内容。Json主体如下:

{
   "resources":{
      "repositories":{
         "self":{
            "refName":"refs/heads/master"
         }
      }
   },
   "variables":{
      "request":{
         "value":"{"key1": "value1"}"  #here, i declare the json string
      }
   }
}

"{"key1": "value1"}"是我要传递的 json 字符串(这只是字符串的一个示例)。

我在大括号前尝试过反斜杠 '' 。"\{"key1": "value1"\}"它没有用。

我试图将大括号放在单引号或双引号之间。"'{'"key1": "value1"'}'" 没用。

你有什么主意吗?也许使用 ServiceNow 的语言是可行的,但我不是它的专家。由于 Azure Devops 只接受字符串作为管道变量,我必须将 json 作为字符串发送。

标签: jsonazure-devopsazure-pipelinesazure-devops-rest-apiservicenow

解决方案


您必须转义该值的双引号:

{\"key1\": \"value1\"}

推荐阅读