本文介绍了如何在Python中创建JSON对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要以以下格式创建JSON对象.怎么做
Hi I need to create a JSON object in the following format. How to go about it
{"user2_proximity": 3, "Wifi_1": -80, "Wifi_2": -40, "Wifi_3": -40,
"thermostat": 18, "light": 0, "hour_of_day": 0, "user3_proximity": 3,
"user1_proximity": 1, "day_of_week": 1, "security": 0, "minute_of_hour": 9,
"Act_1": 1, "Act_2": 0, "Act_3": 0}
推荐答案
源: https: //docs.python.org/2/library/json.html
import json
data = {"user2_proximity": 3, "Wifi_1": -80, "Wifi_2": -40, "Wifi_3": -40,
"thermostat": 18, "light": 0, "hour_of_day": 0, "user3_proximity": 3,
"user1_proximity": 1, "day_of_week": 1, "security": 0, "minute_of_hour": 9,
"Act_1": 1, "Act_2": 0, "Act_3": 0}
json_data = json.dumps(data)
这篇关于如何在Python中创建JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!