Created
December 19, 2012 04:23
-
-
Save makotoworld/4334367 to your computer and use it in GitHub Desktop.
python で json を解析、出力する
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
import simplejson | |
## 書き出し | |
sample = {"@title": "みんなのPython", "author": "柴田淳", "pub": ["SoftBank Creative", "2006"]} | |
file = open("sample.json", "w") | |
simplejson.dump(sample, file, indent=3) | |
## sample.jsonの中身 | |
#{ | |
# "@title": "みんなのPython", | |
# "pub": [ | |
# "SoftBank Creative", | |
# "2006" | |
# ], | |
# "author": "柴田淳" | |
#} | |
## 読み込み | |
file = open("sample.json") | |
a = simplejson.load(file) | |
a["@title"] | |
# >> u"みんなのPython" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment