2.1JSON資料格式

來源:互聯網
上載者:User

標籤:not   格式   ensure   平台   描述   pytho   內容   asc   dump   

本節內容:

1、JSON介紹

2、JSON資料解析

3、執行個體

 

1、JSON介紹

JSON指的是JavaScript對象標記法(JavaScript Object Notation)

JSON是輕量級的文本資料交換格式

JSON獨立於語言,JSON使用JavaScript文法來描述資料對象,獨立於語言和平台

2、JSON資料解析

python使用json模組對JSON資料進行編解碼

  • json.dumps():對資料進行編碼
  • json.loads():對資料進行解碼

執行個體:

 

test_dict = {"name":"yangyang","None":None,"age":25,"mail":False,"graduation":["shaoyangxue",1222]}
dict_to_json = json.dumps(test_dict)
print type(dict_to_json)
print dict_to_json

json_to_dict = json.loads(dict_to_json)
print type(json_to_dict)
print json_to_dict

 

3、執行個體

import json

if __name__ =="__main__":
name = raw_input("請輸入你的姓名:")
number = raw_input("請輸入您的號碼:")
person_dict = \
{
"name" : name,
"number" : number
}
person_json = json.dumps(person_dict,ensure_ascii= False,indent = 4)

print type(person_json)
print person_json

 

 

 

2.1JSON資料格式

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.