JSON はデータを格納するための構文です.
JSON は JavaScript.
Python は json、JSON.
import json
メソッド json.loads() Python.
の結果はPython辞書に格納されます.
import json
x = '{ "name":"patrik", "age":25, "city":"Paris"}'
# パーサー x:
y = json.loads(x)
print(y["city"])
method を使用して Python オブジェクトを変換できます json.dumps().
import json
# object
x = {"name": "patrik", "age": 25, "city": "Paris"}
# JSON に変換:
y = json.dumps(x)
# 結果は JSON
print(y)
Python オブジェクトは、さまざまなタイプの JSON に変換できます:
import json
x = {
"name": "Adam",
"age": 32.
"single": False,
"children": ("Leo","Arthur"),
"car": [
{"model": "Renault", "year": 2022},
]
}
print(json.dumps(x, indent=4))
Result:
{
"名前": "Adam",
"age": 32,
"single": false,
"children": [
"L\u00e9o",
"Arthur"
],
"車": [
{
"model": "Renault",
"年": 2022
}
]
}
json.dumps(x, indent=4, sort_keys=True)
Please disable your ad blocker and refresh the window to use this website.