我有一系列数据要输入数据库。输入数据的用户界面不适用于批量输入,因此我尝试制定等效的命令行。当我检查Chrome中UI的网络请求时,看到了json对象的PUT请求。当我尝试复制请求时
curl -H 'Accept: application/json' -X PUT '{"tags":["tag1","tag2"],"question":"Which band?","answers":[{"id":"a0","answer":"Answer1"},{"id":"a1","answer":"answer2"}]}' http://example.com/service`
我得到一个错误
curl:(3)位置X不支持[globbing]嵌套括号
其中X是第一个“ [”的字符位置。
如何放置包含数组的json对象?
您的命令行应该在要发送到PUT中的字符串之前插入-d /-数据,并且您要设置Content-Type而不是Accept。
curl -H 'Content-Type: application/json' -X PUT -d '[JSON]' http://example.com/service
使用问题中的确切JSON数据,完整的命令行将变为:
curl -H 'Content-Type: application/json' -X PUT \ -d '{"tags":["tag1","tag2"],"question":"Which band?","answers":[{"id":"a0","answer":"Answer1"},{"id":"a1","answer":"answer2"}]}' \ http://example.com/service