首页 > 其他分享 > 从string中生成dict

从string中生成dict

时间:2023-02-20 18:01:58浏览次数:63  
标签:string python 生成 json dict https original

20230220

using json.loads().

import json
original_string = '{"John" : "01", "Rick" : "02", "Sam" : "03"}' 
  
# printing original string 
print("The original string is : " + str(original_string))
  
# using json.loads() method
result = json.loads(original_string)
  
# print result
print("The converted dictionary is  : " + str(result))

最好是""双引号。json默认双引号内的是dict。

参考:
[1] https://favtutor.com/blogs/string-to-dict-python
[2] https://stackoverflow.com/questions/39491420/python-jsonexpecting-property-name-enclosed-in-double-quotes
[3] https://www.geeksforgeeks.org/python-program-to-create-a-dictionary-from-a-string/
[4] https://favtutor.com/blogs/string-to-dict-python

标签:string,python,生成,json,dict,https,original
From: https://www.cnblogs.com/xiaoxu-xli/p/17138391.html

相关文章