简体   繁体   English

如何强制Firebug按声明的顺序打印JSON属性?

[英]How can I force Firebug to print my JSON properties in the order they are declared?

I'm building JSON with JavaScript. 我正在用JavaScript构建JSON。 Here's my object: 这是我的对象:

catalogoJSON = {
    condicion: condicionCatalogos0,
    tipo: tipoCatalogos0,
    idCatalogo: idCatalogo0,
    valor: valorCatalogos0
};

But when I print it with Firebug, I get my properties printed alphabetically like this: 但是,当我用Firebug打印时,我的属性按字母顺序打印如下:

{
    condicion: condicionCatalogos0,
    idCatalogo: idCatalogo0,
    tipo: tipoCatalogos0,
    valor: valorCatalogos0
}

Is there a way in JavaScript to get back my JSON with its properties in the order that I declare them, without having to change my properties' names? JavaScript中是否有一种方法可以按声明的顺序取回其属性的JSON,而无需更改属性名称?

Objects in JavaScript have no inherit order. JavaScript中的对象没有继承顺序。 Firebug just prints then alphabetically, because it feels like it (Chrome's dev tools to that too). Firebug只是按字母顺序打印,然后再按字母顺序打印,因为感觉就像Chrome浏览器的开发工具一样。

You can try to loop through the object, and print it yourself, that may keep the order. 您可以通过对象尽量循环,自己打印, 可以保持这个顺序。

for(var x in catalogoJSON){
    console.log(x, catalogoJSON[x]);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM