Python簡單讀取json文件功能示例
本文實例講述了Python簡單讀取json文件功能。分享給大家供大家參考,具體如下:
read_json.json:
{ "rule":{ "namespace":"strategy", "name":"test_exp_1496234234223400", "version":0, "last_modify_time":1434234236819000, "log_rate":1023300, "schema_version":"hello_world!" } }
read_json.py:
# -*- coding:utf-8 -*- import json with open("read_json.json", 'r') as f: temp = json.loads(f.read()) print(temp) print(temp['rule']) print(temp['rule']['namespace'])
運行結果:
{u'rule': {u'name': u'test_exp_1496234234223400', u'log_rate': 1023300, u'namespace': u'strategy', u'schema_version': u'hello_world!', u'last_modify_time': 1434234236819000L, u'version': 0}} {u'name': u'test_exp_1496234234223400', u'log_rate': 1023300, u'namespace': u'strategy', u'schema_version': u'hello_world!', u'last_modify_time': 1434234236819000L, u'version': 0} strategy
PS:關于json操作,這里再為大家推薦幾款比較實用的json在線工具供大家參考使用:
在線JSON代碼檢驗、檢驗、美化、格式化工具:
http://tools.jb51.net/code/json
JSON在線格式化工具:
http://tools.jb51.net/code/jsonformat
在線XML/JSON互相轉換工具:
http://tools.jb51.net/code/xmljson
json代碼在線格式化/美化/壓縮/編輯/轉換工具:
http://tools.jb51.net/code/jsoncodeformat
在線json壓縮/轉義工具:
http://tools.jb51.net/code/json_yasuo_trans
更多Python相關內容感興趣的讀者可查看本站專題:《Python操作json技巧總結》、《Python編碼操作技巧總結》、《Python數據結構與算法教程》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》、《Python入門與進階經典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設計有所幫助。
相關文章
Python Matplotlib 基于networkx畫關系網絡圖
這篇文章主要介紹了Python Matplotlib 基于networkx畫關系網絡圖,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-07-07