用#'#'开头读取带有键的json对象字符

时间:2015-05-26 16:19:43

标签: javascript jquery ajax json

我的JSON结构如下

"{"Key":{"#text":"100150410150347261963/output/Five String.mp4"},"LastModified":{"#text":"2015-05-26T15:33:39.000Z"},"ETag":{"#text":"\"5e5fd36802186f81109a9adedcb802fe\""},"Size":{"#text":"18831126"},"StorageClass":{"#text":"STANDARD"}}"

这是我的代码

var data = JSON.parse("{"Key":{"#text":"100150410150347261963/output/Five String.mp4"},"LastModified":{"#text":"2015-05-26T15:33:39.000Z"},"ETag":{"#text":"\"5e5fd36802186f81109a9adedcb802fe\""},"Size":{"#text":"18831126"},"StorageClass":{"#text":"STANDARD"}}");
var key = data.Key;

现在我想读取值'100150410150347261963/output/Five String.mp4',但此值的关键是'#text',它以#字符开头。我怎么读这个?

var value = key.#text;

var value = key.'#text';

无效。有没有办法读这个值?

PS:请忽略双重引用&{39; "'字符

1 个答案:

答案 0 :(得分:2)

使用括号表示法:

var value = data.Key['#text'];