Retrieving a property of a JSON object by index?

后端 未结 11 1006
情书的邮戳
情书的邮戳 2020-12-02 13:28

Assuming this JSON object:

var obj = {
    \"set1\": [1, 2, 3],
    \"set2\": [4, 5, 6, 7, 8],
    \"set3\": [9, 10, 11, 12]
};

The \"set

11条回答
  •  被撕碎了的回忆
    2020-12-02 13:48

    """
    This could be done in python as follows.
    Form the command as a string and then execute
    """
    context = {
        "whoami": "abc",
        "status": "0",
        "curStep": 2,
        "parentStepStatus": {
            "step1":[{"stepStatus": 0, "stepLog": "f1.log"}],
            "step2":[{"stepStatus": 0, "stepLog": "f2.log"}]
        }
    }
    def punc():
              i = 1
              while (i < 10):
                  x = "print(" + "context" + "['parentStepStatus']" + "['%s']"%("step%s")%(i) + ")"
                  exec(x)
                  i+=1
    punc()
    

提交回复
热议问题