如何在 HTTP 请求的 JSON 正文中传递 JSON 字符串?

How to pass JSON string in the JSON body of an HTTP request?

如何在 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 作为字符串发送。

您必须转义值的双引号:

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