如何在 python 中获取 JSON 文档作为用户输入
How to get JSON document as user input in python
我正在使用 mongoDB 和 python 。我希望用户以 JSON 格式输入文档,以便我可以将其插入到我的数据库中的某个集合中。如何做到这一点?
如这个类似问题所示,Choosing a file in Python with simple Dialog :
from Tkinter import Tk
from tkFileDialog import askopenfilename
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file
print(filename)
import json
#read string input
dataone= raw_input()
m=json.loads(dataone)
print (m["attribute name in double quotes "])
如果用户输入这个字符串 {"name":"joe","age":18,"hobby":"singing"}
m["name"] 将给出输出 joe.
我正在使用 mongoDB 和 python 。我希望用户以 JSON 格式输入文档,以便我可以将其插入到我的数据库中的某个集合中。如何做到这一点?
如这个类似问题所示,Choosing a file in Python with simple Dialog :
from Tkinter import Tk
from tkFileDialog import askopenfilename
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file
print(filename)
import json
#read string input
dataone= raw_input()
m=json.loads(dataone)
print (m["attribute name in double quotes "])
如果用户输入这个字符串 {"name":"joe","age":18,"hobby":"singing"} m["name"] 将给出输出 joe.