json - 如何在 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 作为字符串发送。
解决方案
您必须转义该值的双引号:
{\"key1\": \"value1\"}
推荐阅读
- c - NOOB C 编程问题:我无法将从文件中读取的值插入到整个代码中的其他变量中
- android - 图像视图像素
- php - Wordpress 主题:仅显示一个类别
- c++ - 如何在 C++ 中使用 new[ ] 和 delete[ ] 运算符
- dart - 在颤动中使用 listview.builder 的水平不可滚动列表
- sql - 如何使用多个表使用“AS”关键字修复 Oracle 错误“ORA-00933:SQL 命令未正确结束”?
- c - 如何创建一个字符串,按字符添加一个字符
- asp.net - ubuntu上从骑手到mircorsoft sql server的连接字符串
- dialogflow-es - Dialogflow 电话网关列表
- android - 用特定颜色填充可绘制对象的透明部分