#author("2018-07-23T06:46:51+00:00","default:masatomix","masatomix")

 $ cat ObjSample.py
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
 
 import sys
 import json
 
 def main(args):
 
     # Dictioinary 型を使ってオブジェクトを定義
     headers2 = dict()
     headers2["Accept"] = "application/json"
     headers2["Content-type"] = "application/json"
 
 
     # JSON形式で、オブジェクトを定義
     headers1 ={
         "Accept": "application/json",
         "Content-type": "application/json"
     }
 
 
 
     # JSON文字列から、オブジェクトを定義
     headers3str = '''
     {
         "Accept": "application/json",
         "Content-type": "application/json"
     }
     '''
 
     headers3 = json.loads(headers3str)
 
     print(headers1)
     print(headers2)
     print(headers3)
 
     print(headers1["Accept"])
     print(headers2["Accept"])
     print(headers3["Content-type"])
 
 
 if __name__ == "__main__":
     main(sys.argv)
 
 
実行結果:
 $ sudo python3 ObjSample.py
 {'Accept': 'application/json', 'Content-type': 'application/json'}
 {'Accept': 'application/json', 'Content-type': 'application/json'}
 {'Accept': 'application/json', 'Content-type': 'application/json'}
 application/json
 application/json
 application/json



トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS