Instantly share code, notes, and snippets.

Embed
What would you like to do?
JsonTest
## -*- coding: utf-8 -*-
import json
#Dic型を作成する
jsonData = {'python':"test"}
enc = json.dumps(jsonData)
print enc
#Result : {"python": "test"}
dec = json.loads(enc)
print dec
#Result : {u'python': u'test'}
#Jsonの外部ファイルを読み込み
f = open('jsonTest.json','r')
#load(FileObj)で読み込み、loadするとDic型で値を取得できる。
jsonD = json.load(f)
print type(jsonD)
#Result : <type 'dict'>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment