如何使用名称中的前导数字访问属性 [英] How to access property with leading numbers in name

查看:72
本文介绍了如何使用名称中的前导数字访问属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var jsonJSON = UrlFetchApp.fetch("https://wowtoken.info/snapshot.json");
var json = Utilities.jsonParse(jsonJSON.getContentText());

var max24 = json.NA.formatted.24max;

我确定我的代码很邋but但是,我得到了Missing; before statement。从底线。当我删除'24'时它会消失,但来源本身有'24max'。

I'm sure my code is sloppy but, I'm getting "Missing ; before statement." from the bottom line. It goes away when I remove the '24', but the source itself has '24max'.

有没有办法让javascript在这段时间后忽略24?或者前两行代码是错误的?

Is there a way to have javascript ignore the 24 after the period? Or are the top two lines of code wrong?

推荐答案

在解析过程中,不是删除对象名称前面的数字,而是也可以像访问数组元素一样访问对象的属性。

Instead of removing the numbers in front of the object names during parsing, you can also access the object's property like you would access an array element like so.

json.NA.formatted [24max]

JavaScript变量必须以字母开头, $ _ 。这就是你收到错误的原因。

JavaScript variables must begin with a letter, $ or _. That is the reason why you are getting an error instead.

这篇关于如何使用名称中的前导数字访问属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆