简体   繁体   English

如何通过http.request的json参数双引号将dictonary对象传递给Django-rest-framework?

[英]How to pass the dictonary object to Django-rest-framework with double quote by http.request's json parameter?

I got this error message on Django-rest-framework. 我在Django-rest-framework上收到此错误消息。

JSON parse error - Expecting property name enclosed in double quotes: line 1 column 2 (char 1)"
}

Its cause must be single quote, but I passed the json datavia http.request method, like as below. 它的原因必须是单引号,但是我通过http.request方法传递了json数据,如下所示。

r = requests.patch('http://localhost:8000/api/xxxx,headers=self.headers, json=payload)

the payload is dictionary. 有效载荷是字典。

id = 111
paylod = {resultid:{"data":"abc","data2","def"}}

How should I handle this? 我该怎么处理? I appreciate the advise! 我很欣赏这个建议!

添加双引号以在有效负载dict中重新resultid

paylod = {"resultid":{"data":"abc","data2","def"}}

Thanks shaik moeed, I found my mistake. 谢谢shaik moeed,我发现了我的错误。 I checked the functionality on django-rest-framework with raw input form, But in this time, I use json parameter on http.request, thus I do not need consider single quote or double quote. 我用原始输入表单检查了django-rest-framework上的功能,但是在这个时候,我在http.request上使用了json参数,因此我不需要考虑单引号或双引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以在没有请求对象的情况下调用django-rest-framework视图? - Is it possible for django-rest-framework view to be called without a request object? 如何使用 django-rest-framework 获取 url 的参数 - How can I get a parameter of an url with django-rest-framework 如何在django-rest-framework中将参数传递给序列化器? - How to pass arguments to a Serializer in django-rest-framework? 如何使用django-rest-framework反序列化嵌套的相关JSON数据? - How to deserialize nested related JSON Data with django-rest-framework? 如何使用 Django-Rest-Framework 返回单个对象 - How to return a single object with Django-Rest-Framework 如何在 django-rest-framework 的序列化器中使用时区序列化时间? - how to serialize time with timezone in django-rest-framework's serializer? 如何通过Django-Rest-Framework中的数据属性重构数据? - How to restructuring the data by the data's property in Django-Rest-Framework? 如何为django-rest-framework api编写单元测试? - How to write unit tests for django-rest-framework api's? 如何在Django-Rest-Framework中检索OneToOneField关系的对象属性 - How to retrieve object attributes of an OneToOneField relation in Django-Rest-Framework django-rest-framework 接受 JSON 数据? - django-rest-framework accept JSON data?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM