如何使用curl将一个json对象与一个数组 [英] How to PUT a json object with an array using curl

查看:2216
本文介绍了如何使用curl将一个json对象与一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列数据进入数据库。用户界面输入数据不利于批量输入,所以我试图制定一个等同的命令行。当我在chrome中检查UI的网络请求,我看到一个json对象的PUT请求。当我尝试复制请求

I have a series of data to enter into database. The user interface to enter the data isn't good for bulk entry, so I'm trying to formulate a command line equivalent. When I examine the network request of the UI in chrome, I see a PUT request of a json object. When I try to replicate the request

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)[globbing] pos X不支持嵌套大括号

curl: (3) [globbing] nested braces not supported at pos X

其中X是第一个[。的字符位置。

Where X is the character position of first "[".

包含数组?

推荐答案

您的命令行应该有一个 - d / - data 在您要在PUT中发送的字符串之前插入,并且要设置Content-Type而不是接受。

Your command line should have a -d/--data inserted before the string you want to send in the PUT, and you want to set the Content-Type and not Accept.


curl -H'Content-Type:application / json'-X PUT -d'[JSON]'
http://example.com/service

使用问题中的确切JSON数据,完整的命令行将变为:

Using the exact JSON data from the question, the full command line would become:


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

这篇关于如何使用curl将一个json对象与一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆