Advertisement
hivefans

read write json

Sep 19th, 2018
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. data.json
  2. [{"need_key": {"pri": ["outpatient_visit_id", "inpatient_visit_id"], "sub": "visit_id"}, "match_rules": [{"pri": ["visit_datetime", "admit_datetime"], "sub": ["create_application_datetime"]}], "principal_table": ["tbl_reg_registrations", "tbl_adt_admits_discharges"], "subordinate_table": "tbl_std_studies", "need_yidu_vid": "yes", "common_key": {"pri": "patient_id", "sub": "patient_id"}}]
  3.  
  4. 如果你要处理的是文件而不是字符串,你可以使用 json.dump() 和 json.load() 来编码和解码JSON数据。例如:
  5. #!/usr/bin/env python
  6. # -*- coding: utf-8 -*-
  7. import json
  8. import os,sys
  9.  
  10. with open('data.json', 'r') as f:
  11.     data = json.load(f)
  12.     print(data[0]["need_yidu_vid"])
  13.  
  14. # Writing JSON data
  15. with open('data.json', 'w') as f:
  16.     json.dump(data, f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement