「Python」JSON文字列を辞書に変換する

書式
json.loads()JSON形式の文字列を辞書に変換する
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import json
# jsonデータの定義:
cft = '{ "username":"yama", "age":30, "city":"東京"}'
# JSONデータをパース:
res = json.loads(cft)
# Python辞書を返す
print(res["age"])
print(res["city"])
import json # jsonデータの定義: cft = '{ "username":"yama", "age":30, "city":"東京"}' # JSONデータをパース: res = json.loads(cft) # Python辞書を返す print(res["age"]) print(res["city"])
import json

# jsonデータの定義:
cft = '{ "username":"yama", "age":30, "city":"東京"}'

# JSONデータをパース:
res = json.loads(cft)

# Python辞書を返す
print(res["age"])
print(res["city"])

結果
30
東京

Python

Posted by arkgame