「python入門」json.dumpメソッドを利用するサンプル

サンプルコード
jsondata = {‘yamada’: {‘city’: {‘age’: 30, ‘salary’: 2500}},’changfa’: ‘wenzho’, ‘guide’: ‘carinfo’}

with open(“result.json”, “w”, encoding=’utf-8′) as writejson
json.dump(jsondata,writejson, ensure_ascii=False, indent=4, sort_keys=False, separators=(‘,’, ‘: ‘))

結果
{
“changfa”: “wenzho”,
“guide”: “carinfo”,
“yamada”: {
“city”: {
“age”: 30,
“salary”: 2500
}
}
}

Comments are closed.