Created
March 5, 2014 14:19
-
-
Save fereria/9368043 to your computer and use it in GitHub Desktop.
JsonTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## -*- 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