我正在Python中使用烧瓶创建rest,并使用curl命令测试我的函数。
卷发指挥:
$ curl -X POST
-H "Content-Type:application/json"
-d '{"keyword": "2''binders", "country": "xyz", "frequency": "1","url":"www.example.com"}' \
http://127.0.0.1:5000/google输出:
'['New Request', u'**2binders**', u'xyz', u'www.example.com', u'1']'如您所见,在json 2''binders中,我正在传递英寸,但在我的列表中,它正在删除它。
编辑:
Python:json = request.get_json(force=True) print json
发布于 2016-05-18 08:12:18
明白了!
curl -X POST -d‘{“关键字”:“2’\‘\\’绑定”,“国家”:"xyz",“频率”:"1","url":"http://www.example.com/"}‘http://127.0.0.1:5000/google -H’内容-类型:application/json“
发布于 2016-05-18 07:03:11
在curl命令中,尝试使用"keyword": "2\'\'binders"。您需要在-d参数内转义单引号,因为您在-d参数周围使用单引号。
shell变得混乱,并认为您想要字符串连接。例如,shell正在看到'abc''def',并将其解释为'abcdef'。
发布于 2016-05-18 07:23:53
如果您尝试json.dumps字典本身:
>>> s = json.dumps(d)
>>>
>>> s
'{"url": "www.example.com", "country": "xyz", "frequency": "1", "keyword": "2\'\'binders"}'
^ ^您将看到它将自动转义',正如前面的答案所提到的,转义它应该对您有好处:
>>> json.loads(s)
{u'url': u'www.example.com', u'country': u'xyz', u'frequency': u'1', u'keyword': u"2''binders"} #Single quote is backhttps://stackoverflow.com/questions/37292359
复制相似问题