[英]Sending JSON with AJAX to Flask Syntax Error
url: '/upload',
type: 'POST',
data: JSON.stringify(pdata),
contentType: "application/json; charset=utf-8",
dataType: "text",
is what I'm using to POST the JSON and it is sending it with the double quotes needed 这就是我用来发布JSON的内容,它使用所需的双引号将其发送
but in flask 但在烧瓶中
content = request.get_json()
gives me content with the double quotes swapped with single quotes 使我满意,双引号与单引号互换
for example {"S":[],"R":[]} goes to {'S':[],'R':[]} 例如{“ S”:[],“ R”:[]}转到{'S':[],'R':[]}
it is something I'm doing wrong or do I need to somehow convert this back to two quotes if I want to send this to a javascript program? 这是我做错了,还是如果我想将其发送到javascript程序,是否需要以某种方式将其转换回两个引号?
request.get_json() returns a python dictionary with values of double-quoted items represented as strings. request.get_json()返回一个python字典,其双引号项目的值表示为字符串。 When you print a python string it's printed with single quotes by default. 当您打印python字符串时,默认情况下会使用单引号将其打印。
When the dictionary is converted back into JSON format you will get doublequotes. 将字典转换回JSON格式后,您将获得双引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.