我无法从我从某个API服务器检索的数据中获取对象属性名称:
var arrData = [{"data":
{"plmn":"Voda","id":"B193","time":1499257121817,"cell":{"rsrp":
[-132.5,-108.88],"rsrq":[-18.69,-6.56],"earfcn":1550,"pci":454,"celltiming":
[252],"sinr":-12.8,10.7]},"mac":"9C65F9"},"time":1499282331405,
},{"data":
{"plmn":"Voda","rssi":-106,"id":"4179","time":315939662698,"cells":
[{"sc":453,"ecno":-19.53,"r99":"intraMon","rscp":-125.53,"ch":10837},
{"sc":452,"ecno":-13.97,"r99":"active","rscp":-119.97,"ch":10837},
{"sc":452,"ecno":-19.53,"r99":"active","rscp":-125.53,"ch":10812},
{"sc":453,"ecno":-19.37,"r99":"intra","rscp":-125.37,"ch":10812}],"mac":
"9C65F9211012"},"time":1499282452590,"deviceID":"9C65F9211012"}]
我已尝试使用此代码:
var collectField = [];
for (var prop in arrData) {
if (arrData.hasOwnProperty(prop)) {
collectField.push(prop);
}
}
// and still wrong Outputs: [0,1,2,3.....]
console.log(collectField);
我预期的输出结果:
[plmn,id,time,cell,,ecno,cells,rscp..and all of that object field]
希望有人可以帮助解决这个问题。
提前致谢
答案 0 :(得分:0)
<VirtualHost *:9002>
ServerName test.something.com
DocumentRoot "/data/site/web"
<Directory "/data/site/web">
Require all granted
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
<Directory /data/site/web/vendor>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
</Directory>
ErrorLog /data/site/app/logs/error.log
CustomLog /data/site/app/logs/access.log combined
</VirtualHost>
构造不会从数组中检索对象但它的索引。因此,您尝试访问号码for-in
。首先,您需要访问数组成员,然后访问属性,例如。像这样:
hasOwnProperty