当键是数字时,jquery访问json

时间:2013-12-29 08:59:21

标签: jquery json

如果这是显而易见的或以前的回答,请原谅我的无知。我有一个像这样的字符串

var test = {"99":{"ttop":"0","lleft":"0","wwidth":"881","hheight":"78"},
"42":{"ttop":"91","lleft":"110","wwidth":"285","hheight":"26"},
"43":{"ttop":"91","lleft":"490","wwidth":"117","hheight":"26"},
"44":{"ttop":"91","lleft":"5","wwidth":"87","hheight":"26"},
"36":{"ttop":"91","lleft":"630","wwidth":"251","hheight":"26"}} 

我已经阅读了很多关于使用文本标识符访问的内容(例如“first-id”而不是“99”)但我认为我的问题是当我使用id作为id时出错。

非常感谢您的帮助

2 个答案:

答案 0 :(得分:1)

您需要使用bracket notation代替dot notation作为member operator

test['99']

答案 1 :(得分:1)

当属性名称不是有效标识符时,请使用数组语法来访问它:

test["99"]