Python簡單讀取json文件功能示例
本文實(shí)例講述了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'])
運(yùn)行結(jié)果:
{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:關(guān)于json操作,這里再為大家推薦幾款比較實(shí)用的json在線工具供大家參考使用:
在線JSON代碼檢驗(yàn)、檢驗(yàn)、美化、格式化工具:
http://tools.jb51.net/code/json
JSON在線格式化工具:
http://tools.jb51.net/code/jsonformat
在線XML/JSON互相轉(zhuǎn)換工具:
http://tools.jb51.net/code/xmljson
json代碼在線格式化/美化/壓縮/編輯/轉(zhuǎn)換工具:
http://tools.jb51.net/code/jsoncodeformat
在線json壓縮/轉(zhuǎn)義工具:
http://tools.jb51.net/code/json_yasuo_trans
更多Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python操作json技巧總結(jié)》、《Python編碼操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設(shè)計有所幫助。
相關(guān)文章
python+opencv實(shí)現(xiàn)車牌定位功能(實(shí)例代碼)
這篇文章主要介紹了python+opencv實(shí)現(xiàn)車牌定位功能,需要實(shí)現(xiàn)對給定的車牌進(jìn)行車牌識別,本文通過實(shí)例代碼講解,需要的朋友可以參考下2019-12-12pandas數(shù)據(jù)清洗,排序,索引設(shè)置,數(shù)據(jù)選取方法
下面小編就為大家分享一篇pandas數(shù)據(jù)清洗,排序,索引設(shè)置,數(shù)據(jù)選取方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-05-05django js實(shí)現(xiàn)部分頁面刷新的示例代碼
今天小編就為大家分享一篇django js實(shí)現(xiàn)部分頁面刷新的示例代碼,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-05-05Python Matplotlib 基于networkx畫關(guān)系網(wǎng)絡(luò)圖
這篇文章主要介紹了Python Matplotlib 基于networkx畫關(guān)系網(wǎng)絡(luò)圖,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07