鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ 循環(huán)遍歷請(qǐng)求返回的json數(shù)據(jù)

循環(huán)遍歷請(qǐng)求返回的json數(shù)據(jù)

"apiList: [
            {`請(qǐng)輸入代碼`
                "method": "GET",
                "version": "1",
                "authtype": "apikey",
                "resulttype": "json",
                "inputList": [
                    {
                        "default": "",
                        "name": "ApiKey",
                        "description": "ApiKey",
                        "location": "header",
                        "type": "varchar",
                        "requires": "1"
                    },
                    {
                        "default": "",
                        "name": "page",
                        "description": "頁數(shù)",
                        "location": "query",
                        "type": "varchar",
                        "requires": "1"
                    },
                    {
                        "default": "",
                        "name": "limit",
                        "description": "每頁顯示數(shù)量",
                        "location": "query",
                        "type": "varchar",
                        "requires": "1"
                    }
                ],
                "outputList": [
                    {
                        "name": "QYHCCSJYX",
                        "description": "遷移或拆除省級(jí)以下(含省級(jí))文物保護(hù)單位審批文件"
                    }
                ]
            }
        ]

上述是請(qǐng)求返回的數(shù)據(jù)格式,如何遍歷獲取inputList、outputList數(shù)組?

回答
編輯回答
焚音

不是很明白你的意思, 問題描述的不清晰

如果 apiList.length === 1, 那么 inputList = apiList[0]['inputList'];

如果 apiList.length > 1 那么也就是加個(gè)循環(huán)

let inputLists = []
apiList.forEach((item, index) => {
    inputList.push(item.inputList)
})
2017年6月14日 18:48