python json 资料判断 true 或 false

我从某个地方获得了一些 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

追问

所以我不能把取得的 true 用新的变数定义 ?

追答

转换为dict对象后,True是值(key = 'test'),是你判断的内容。

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网