Home >Backend Development >PHP Tutorial > 如题在JS中获取JSON中的数据解决方案

如题在JS中获取JSON中的数据解决方案

WBOY
WBOYOriginal
2016-06-13 12:57:11919browse

如题在JS中获取JSON中的数据
var newValue = {"1051431":"0","1051569":"0"};
var itemnum = arrValue[0];

alert(newValue.itemnum);

这样打印出undefined


------解决方案--------------------
var data = eval("("+newValue+")");//js 解析json数据,主要是因为json数据用单引号后变为字符串了

alert(data[itemnum]);

对于键名为数字或者非正常变量字符时(如有空格),必须使用obj[xx]方式获取值。
Statement:
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 admin@php.cn