JSON (全名: JavaScript Object Notation對象表示法)是一種輕量級的文本數據交換格式, JSON的數據格式其實就是python裡面的
字典格式,Faces can contain arrays enclosed in parentheses,也就是python裡面的列表.
{
"_id": 1,
"name": "ZJ",
"age": 22,
"date": "2022.08.03"
}
json字符串轉換成python對象
>>> import json
>>> body = {
"Text":"You are so beautiful"}
>>> jsonob = json.dumps(body)
>>> jsonob
'{"Text": "You are so beautiful"}'
>>> json.loads(jsonob)
{
'Text': 'You are so beautiful'}
python對象轉換成json字符串
#字符串轉換json對象
>>> import json
>>> body='{"Text":"you are nice girl"}'
>>> type(body)
<class 'str'>
>>> json.dumps(body)
'"{\\"Text\\":\\"you are nice girl\\"}"'
# dict轉換為json對象
>>> import json
>>> body = {
"Text":"You are so beautiful"}
>>> json.dumps(body)
'{"Text": "You are so beautiful"}'
>>>
將python數據類型轉換並保存到json格式的文件內
將jsonThe data in the file in the format is read and converted topython類型