Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.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
在cURL中未定义Json_Json_Curl_Jira Rest Java Api - Fatal编程技术网

在cURL中未定义Json

在cURL中未定义Json,json,curl,jira-rest-java-api,Json,Curl,Jira Rest Java Api,我需要在Jira中自动插入问题,所以我需要使用restapi,从命令行运行curl,下面是我的命令 C:\WINDOWS\system32>curl.exe -D- -u fred:fred -X POST --data { "fields": {"project": { "key"="ZZZ-180" }, "summary": "REST TESTING" , "description": "Creation of a testing issue" , "issuretype" { "

我需要在Jira中自动插入问题,所以我需要使用restapi,从命令行运行curl,下面是我的命令

C:\WINDOWS\system32>curl.exe -D- -u fred:fred -X POST --data { "fields": {"project": { "key"="ZZZ-180" }, "summary": "REST TESTING" , "description": "Creation of a testing issue" , "issuretype" { "name": "Bug"}}} -H "Content-Type: application/json" http://ABCD.com:XXXX/rest/api/2/issue/
以下是我收到的:

curl: (6) Could not resolve host: fields
curl: (3) [globbing] unmatched brace at pos 10
curl: (3) [globbing] unmatched brace at pos 2
curl: (6) Could not resolve host: key=
curl: (6) Could not resolve host: ZZZ-180
curl: (3) [globbing] unmatched close brace/bracket at pos 1
curl: (6) Could not resolve host: summary
curl: (6) Could not resolve host: REST TESTING
curl: (6) Could not resolve host: ,
curl: (6) Could not resolve host: description
curl: (6) Could not resolve host: Creating of a testing issue
curl: (6) Could not resolve host: ,
curl: (6) Could not resolve host: issuretype
curl: (3) [globbing] unmatched brace at pos 2
curl: (6) Could not resolve host: name
curl: (3) [globbing] unmatched close brace/bracket at pos 4

有谁能帮我让cURL定义用数据编写的JSON代码吗?

您必须引用字符串,但最简单的方法是将JSON数据放入文件中,并让cURL从中读取:

C:\WINDOWS\system32>curl.exe -D- -u fred:fred -X POST --data @data_to_send.json -H "Content-Type: application/json" http://ABCD.com:XXXX/rest/api/2/issue/
注意文件名前面的
@

您的--data应该类似于:

"{ \"fields\": {\"project\": { \"key\"=\"ZZZ-180\" }, \"summary\": \"REST TESTING\" , \"description\": \"Creation of a testing issue\" , \"issuretype\" { \"name\": \"Bug\"}}}"

您必须引用参数,否则curl将使用
{
作为数据,并将其他部分解释为参数(未知)…我尝试过,但仍然是相同的错误,还删除了空格
{“字段”:{
@Blundell。我的例子是字符串上的空格。对我的理解很不寻常。谢谢。我尝试过,但JSON代码仍然完全没有定义。如何在curl中识别JSON,,,我以前从未使用过JSON,很抱歉我不知道如何安装JSON在curl中使用。你不必安装JSON,JSON是一种文件格式;)curl只需将
数据\u的内容传输到发送.json即可:将json字符串放入其中并导航到文件夹或提供完整路径(如
--data C:\path\to\data\u to\u发送.json
)。非常感谢,,,现在的问题是对REST API的授权!无论如何,谢谢。我试图用perl脚本编写此命令以传递给命令提示符…我使用了回溯``但它总是在JSON文件路径之前给出@符号的错误…有什么建议吗?如何引用字符串?