Home > Web Front-end > JS Tutorial > body text

当json键为数字时的取值方法解析_javascript技巧

php.cn
Release: 2016-05-16 17:15:00
original
1319 people have browsed it

当json的键为数字时如何取值,如:
var aa={'111':'aaaaa'};
alert(sss.111);
这样是不行的,alert不会弹任何东西。

json的键必须是一个对象,才能取出东西,如:
var aa={'s111s':'aaaaa'};
var idd="s111s";
alert(sss.idd);


解答:

对于数字键名或者非正常变量字符(比如有空格),必须使用 aa[x]的方式。
var aa={'111':'aaaaa'};
alert(sss["111"]);

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Latest issues
Popular Tutorials
More>
Latest downloads
More>
web effects
Website source code
Website materials
Front end template
About us Disclaimer Sitemap
PHP Chinese website:Public welfare online PHP training,Help PHP learners grow quickly!