I am trying to send some JSON to my django app in a query string by using encodeURIComponent() my server enpoint receives the data just fine as I can print it to the python console.print request.GET下面一行的输出就是这种格式The output of the following line is in this format<QueryDict: {u'[my json array]': [u''}}>我想将其转换为 JSON 以便我可以用来获取一些信息,但我已经尝试使用 json.loads 和其他操作数据的方法,但没有运气.I want to convert this to JSON so I can use to get some information but I've tried using json.loads and other means of manipulating the data with no luck.我的输出应该是这样的[{u'something': something}, {u'something1': something2}, {u'something3': something3}]关于我在这里做错的任何提示?Any tips as to what I am doing wrong here?推荐答案QueryDict 类是子类常规 Python 字典,除了它处理同一个键的多个值(参见 code>MultiValueDict 实现).QueryDict class is a subclass of regular Python dictionary, except that it handles multiple values for a same key (see MultiValueDict implementation).如果你想把它转储到一个字符串,只需使用json.dumps():If you want to dump it to a string, just use json.dumps():json.dumps(my_query_dict)还有一个相关的dict() 方法:There is also a relevant dict() method:QueryDict.dict() QueryDict.dict()返回 QueryDict 的字典表示.Returns dict representation of QueryDict. 这篇关于Python:查询字典到 JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-13 22:29