Skip to content

Instantly share code, notes, and snippets.

@fereria
Created March 5, 2014 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fereria/9368043 to your computer and use it in GitHub Desktop.
Save fereria/9368043 to your computer and use it in GitHub Desktop.
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