SHARE
TWEET

read write json

hivefans Sep 19th, 2018 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top