python附加到json对象中的数组 [英] python append to array in json object

查看:31
本文介绍了python附加到json对象中的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 python 中有以下 json 对象:

I have the following json object in python:

jsonobj = {
          "a": {
              "b": {
                      "c": var1,
                      "d": var2,
                      "e": [],
                   },

                },
            }

我想将键值元素附加到e"中,但无法弄清楚它的语法.我尝试附加以下内容,但括号和引号不正确:

And I would like to append key-value elements into "e", but can't figure out the syntax for it. I tried appending with the following, but it doesn't come out right with the brackets and quotes:

jsobj["a"]["b"]["e"].append("'f':" + var3)

相反,我希望e"如下:

Instead, I want "e" to be the following:

"e":[
       {"f":var3, "g":var4, "h":var5},
       {"f":var6, "g":var7, "h":var8},
    ]

有谁知道附加到这个 json 数组的正确方法吗?非常感谢.

Does anyone know the right way to append to this json array? Much appreciation.

推荐答案

jsobj["a"]["b"]["e"].append({"f":var3, "g":var4, "h":var5})
jsobj["a"]["b"]["e"].append({"f":var6, "g":var7, "h":var8})

这篇关于python附加到json对象中的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆