乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Python JSON 

       小飛苑 2017-01-02

      本章節(jié)我們將為大家介紹如何使用 Python 語言來編碼和解碼 JSON 對象。


      環(huán)境配置

      在使用 Python 編碼或解碼 JSON 數(shù)據(jù)前,我們需要先安裝 JSON 模塊。本教程我們會下載 Demjson 并安裝:

      $ tar xvfz demjson-1.6.tar.gz
      $ cd demjson-1.6
      $ python setup.py install
      

      JSON 函數(shù)

      函數(shù)描述
      encode 將 Python 對象編碼成 JSON 字符串
      decode將已編碼的 JSON 字符串解碼為 Python 對象

      encode

      Python encode() 函數(shù)用于將 Python 對象編碼成 JSON 字符串。

      語法

      demjson.encode(self, obj, nest_level=0)
      

      實例

      以下實例將數(shù)組編碼為 JSON 格式數(shù)據(jù):

      #!/usr/bin/python
      import demjson
      
      data = [ { 'a' : 1, 'b' : 2, 'c' : 3, 'd' : 4, 'e' : 5 } ]
      
      json = demjson.encode(data)
      print json
      

      以上代碼執(zhí)行結(jié)果為:

      [{"a":1,"b":2,"c":3,"d":4,"e":5}]
      

      decode

      Python 可以使用 demjson.decode() 函數(shù)解碼 JSON 數(shù)據(jù)。該函數(shù)返回 Python 字段的數(shù)據(jù)類型。

      語法

      demjson.decode(self, txt)
      

      實例

      以下實例展示了Python 如何解碼 JSON 對象:

      #!/usr/bin/python
      import demjson
      
      json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
      
      text = demjson.decode(json)
      print  text
      

      以上代碼執(zhí)行結(jié)果為:

      {u'a': 1, u'c': 3, u'b': 2, u'e': 5, u'd': 4}
      

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多