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})