お世話になります。今下記で勉強中です。
http://docs.python.jp/2.7/tutorial/inputoutput.html
オブジェクト x があり、その JSON 形式の文字列表現を見るには、単純な1行のコードを書くだけです:
json.dumps([1, 'simple', 'list'])
'[1, "simple", "list"]'
上記はうまくいきました
dumps() に似た関数に、dump() があり、こちらは単純にオブジェクトをファイルにシリアライズします。f が書き込み用に開かれた file object だとすると、次のように書くことができます。
json.dump(x, f)
************************************
C:\Users\mtg-1>python
Python 2.7.12 |Anaconda 4.2.0 (64-bit)| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
import json
json.dumps([1, 'simple', 'list'])
'[1, "simple", "list"]'
json.dump(x, f)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
こうなるのはオブジェクト x がないからですがオブジェクト xをどのように生成すればよいのかわかりません。
ご指導ください。よろしくお願いいたします
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/25 05:48