我从某个地方获得了一些 json 的资料如下
{
"test": true,
"once": 0
}
请问我该怎麼用python 写个判断
假如 'test' 为 true 或为 false 就做别的事情 ?
我试著写 myname = ['name']['test']
if myname is True :
print 'yes'
执行後没错误,但也不会 print 我要的结果出来,请问到底是哪里有问题
'name':[
{
"test": true,
"once": 0
}
]
your_data_dict = json.loads(your_json_data_string)
# Here to get a dictionary object. Then you can acccess its key and value
# Maybe, you should pay attention to the data type of value with key 'test'
if your_data_dict['test'] is True:
# do what you want
pass追问
# Here to get a dictionary object. Then you can acccess its key and value
# Maybe, you should pay attention to the data type of value with key 'test'
if your_data_dict['test'] is True:
# do what you want
pass追问
所以我不能把取得的 true 用新的变数定义 ?
追答转换为dict对象后,True是值(key = 'test'),是你判断的内容。
温馨提示:答案为网友推荐,仅供参考