When saving data, the format becomes this mode. There are many such data:
{"status": "0", "msg": "ok", "result": {"name": "Dew", "content": "<p>release name
When the autumn dew is heavy, go to the flowers and plants in the morning to collect it.</p><p>Smell
Sweet, flat and non-toxic.</p>Stop thirst. Baihua Dew: Can make the skin healthy. Cypress Leaf Dew, Calamus Dew: Wash your eyes every morning, can enhance vision.
Leek Leaf Dew: Treat vitiligo. Apply to the affected area every morning. </p>", "commentary": "", "translation": "", "appreciation": "", "interpretation": ""}}
{"status": "0", "msg ": "ok", "result": {"name": "明水", "content": "<p>
世名
is also called Fangzhushui. Fangzhu is one The name of the big clam. On a moonlit night, catch Fang Zhu and take the water stored in its shell. If it is clear and pure, it is Fang Zhu water.</p><p>
Smell Sweet, cold, non-toxic.</p><p>
Indications Used to wash eyes, it can remove fog and improve eyesight. Drinking this water also has a calming effect and can also relieve children's troubles. Hot.</p>", "commentary": "", "translation": ""}}
After type, the format is displayed as a string. I used the built-in function, but it still failed to convert it to the standard dictionary format, as follows:
from pprint import pprint import json import requests
with open('bencao_detail','r',encoding='utf8') as file: str_file = file.read()
The output results are as follows:str_file
'{"status": "0", "msg": "ok", "result": {"name": "Dew", "content": "<p> Name
When the autumn dew is heavy, go to the flowers and plants in the morning to collect it.</p><p>Smell
Sweet, flat, non-toxic.</p> ;<p>Indications
Used to decoct the medicine to moisten the lungs and kill insects, or mix the powder for treating scabies and worms into topical medicine, which can enhance the curative effect.
White Flower Dew : Stop thirst.
Baihua Dew: Can make the skin healthy.
Cypress Leaf Dew, Calamus Dew: Wash your eyes every morning, can enhance vision.
Leek Leaf Dew: Treat vitiligo. Apply to the affected area every morning .</p>", "commentary": "", "translation": "", "appreciation": "", "interpretation": ""}}n{"status": "0", "msg" : "ok", "result": {"name": "明水", "content": "<p>世名
is also called Fangzhushui. Fangzhu is a kind of The name of the big clam. On a moonlit night, catch Fang Zhu and take the water stored in its shell. If it is clear and pure, it is Fang Zhu water.</p><p> Smell
Sweet , cold, non-toxic.</p><p>Indications
Used to wash eyes, it can remove fog and improve eyesight. Drinking this water also has a calming effect and can also relieve irritability in children. .</p>", "commentary": "", "translation": ""}}n{"status": "0", "msg": "ok", "result": {"name": "Winter Frost", "content": "<p>release
How to get the frost: sweep it with chicken feathers, put it into a bottle, seal it and store it in a cool place. Even if it turns into liquid, Li</p><p>Smell
Sweet, cold, non-toxic.</p><p>Indications
Drinking winter frost can To relieve hangover fever, if you feel hot and flushed ears after drinking, drink it and it will disappear immediately. For typhoid fever and nasal congestion, drinking winter frost can also clear your nose. For prickly heat and redness and swelling under the armpits, apply winter frost and clam powder, which is effective. For malaria caused by cold and heat, you can treat autumn frost or winter frost for one and a half qian, along with hot wine, and it will also be effective. </p>", "commentary" : "", "translation": ""}}n
How can I make it a dictionary one by one?
phpcn_u15822017-06-22 11:54:19
In fact, eval is the simplest in this standard dictionary format.
t='''{"status": "0", "msg": "ok", "result": {"name": "露水", "content":
"<p>释名在秋露重的时候,早晨去花草间收取。</p><p>气味甘、平、无毒。</p><p>主治用以煎煮润肺杀虫的药剂,或把治疗疥癣、虫癞的散剂调成外敷药,可以增强疗效。白花露:止消渴。百花露:能令皮肤健好。柏叶露、菖蒲露:每天早晨洗眼睛,能增强视力。韭叶露:治白癜风。每天早晨涂患处。</p>", "commentary": "", "translation": "", "appreciation": "", "interpretation": ""}}'''
a=eval(t)
巴扎黑2017-06-22 11:54:19
You all know import json
, why don’t you ask questions
import json
with open('bencao_detail','r',encoding='utf8') as file:
str_file = file.read()
dict_data = json.loads(str_file)
// 或者
dict_data = json.load(file)