如何使用python在嵌套json中创建对象?
如何使用python在嵌套json中创建对象 范例如何使用python在嵌套json中创建对象?,python,json,Python,Json,如何使用python在嵌套json中创建对象 范例 { friends:{ john:{ height:182 } } } 例如,我将如何在john内部创建另一个名为weight的对象,并使用python将其设置为60kg(只是一个示例) data = {'friends':{'john':{'height':182}}} data['friends']['john']['weight'] = 60 输出: {'fri
{
friends:{
john:{
height:182
}
}
}
例如,我将如何在john内部创建另一个名为weight的对象,并使用python将其设置为60kg(只是一个示例)
data = {'friends':{'john':{'height':182}}}
data['friends']['john']['weight'] = 60
输出:
{'friends': {'john': {'height': 182, 'weight': 60}}}
您可以执行以下操作:
In [1]: x = {
"friends":{
"john":{
"height": 182
}
In [2]: x["friends"]["john"]["weight"] = 60
In [3]: x
Out[3]: {'friends': {'john': {'height': 182, 'weight': 60}}}
这既不是可运行的Python代码示例,也不是有效的JSON语法。请出示一张真实的支票。您必须按照
数据['friends']['john']['weight']=60
使用一些代码,但这很难说。