在胡须模板中,如果密钥的编号来自 JSON 响应,则如何访问密钥


{
"batchcomplete": "",
"query": {
    "normalized": [{
        "from": "india",
        "to": "India"
    }],
    "pages": {
        "14533": {
            "pageid": 14533,
            "ns": 0,
            "title": "India",
            "extract": "India, officially the Republic of India (Bhu0101rat Gau1e47aru0101jya), is a country in South Asia. It is the seventh-largest country by area, the second-most populous country (with over 1.2 billion people), and the most populous democracy in the world. It is bounded by the Indian Ocean on the south, the Arabian Sea on the southwest, and the Bay of Bengal on the southeast."
        }
    }
}
}

在上面的 json 响应中,"14533"是一个页面 ID。对于 API 的每个触发器,该页面 ID 将更改。我想在节点红色的"胡须模板"中动态访问该数字。

你可以

这样做。解析 JSON,然后在页面对象中获取密钥

var obj = JSON.parse('{"batchcomplete": "","query": {"normalized": [{    "from": "india","to": "India"}],"pages": {"14533": {"pageid": 14533,        "ns": 0,    "title": "India", "extract": "India, officially the Republic of India (Bhu0101rat Gau1e47aru0101jya), is a country in South Asia. It is the seventh-largest country by area, the second-most populous country (with over 1.2 billion people), and the most populous democracy in the world. It is bounded by the Indian Ocean on the south, the Arabian Sea on the southwest, and the Bay of Bengal on the southeast."}}}}'); 
console.log(Object.keys(obj.query.pages)[0]);

最新更新