![](/img/trans.png)
[英]Values in python dictionary getting converted to double quotes rather than single quotes
[英]Load json with double quotes rather than single in python
我有一個字符串,最初有雙引號 '{"a":"1","b":"2"}' 並且需要在以后的程序中保留雙引號以簡化程序。
在執行 json.loads 時, " 變成 ' 我需要一種方法來加載原始字符串並允許我調用 ["a"] 並返回帶有雙引號而不是單引號的 "1"
您可以使用:
import json
d = json.loads(s)
print(d["a"])
print(d['a'])
1
1
如您所見,使用d['a']
或d["a"]
'a'
或"a"
是可以互換的,兩者都表示字符串
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.