程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Read multiple JSON files Python

編輯:Python

The data format is as follows :

{
"entity_type": "Person", " Chinese name ": " Tan Yan ", " nationality ": " The British ", " occupation ": " actor / Production / dubbing ", " Date of birth ": "1967 year 7 month 26 Japan ", "url": "/film.kg.huawei.com/ Tan Yan /178128864"}
{
"entity_type": "Person", " Chinese name ": " Su Xin ", " nationality ": " China ", " occupation ": " actor ", " Date of birth ": "1983 year 10 month 23 Japan ", "url": "/film.kg.huawei.com/ Su Xin /84121518"}
{
"entity_type": "Person", " Chinese name ": " Tan Yan ", " nationality ": " The British ", " occupation ": " actor / Production / dubbing ", " Date of birth ": "1967 year 7 month 26 Japan ", "url": "/film.kg.huawei.com/ Tan Yan "}
  1. Read every data in the file first
with open(filename, 'r', encoding='utf8') as fr:
json_filedata = fr.readlines()
  1. Convert data into a dictionary
import ast
for strdata in json_filedata:
test_dict = ast.literal_eval(strdata)

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved