WHM API:每次以随机顺序获取JSON结果

问题描述 投票:0回答:1

我正在使用NodeJS通过WHM API 1获得结果。

我制作了一个异步函数,该函数调用WHM getdiskusage函数并接收结果对象。

我从JSON中获得的结果是它的一对键值具有正确的映射。

但是它们的顺序总是随机的。

WHM API 1 getdiskusage()输出结果的预期顺序https://documentation.cpanel.net/display/DD/WHM+API+1+Functions+-+getdiskusage

var WHM = require('node-whm');
var whmClient = new WHM.Client({
    serverUrl: 'https://my.remotehost.com:2087',
    remoteAccessKey: 'xxxxxxxxxxxxxxxxxxxxxxxxx',
    username: 'xxxxxxxx'
})

async function getDiskInfo() {
    try
        {
            let response = await whmClient.getdiskusage().then(async (token) => { return await token } )
            let data = await response
            return data
        }catch(err){
        console.error('Error: ', err);
    }
}

getDiskInfo()
    .then(data => {
        let d = JSON.parse(data) 
        console.table(d.data.partition)

    }).catch(() => {
        console.error('Error: ', err);
    })
javascript node.js api whm
1个回答
1
投票

不维护JSON元素的顺序,但是会维护JSON数组的顺序。这是js的行为

© www.soinside.com 2019 - 2024. All rights reserved.