使用奇怪的字符访问Json字段 [英] Accessing Json fields with weird characters

查看:122
本文介绍了使用奇怪的字符访问Json字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个json字符串我用一个简单的eval(字符串)转换为对象;

i have a json string im converting to object with a simple eval(string);

heres the sample of the json string:
var json = @'
"{ description" : { "#cdata-section" : "<some html here>" } }
';
var item = eval('('+json+')');

我试图像这样访问它

item.description.#cdata-section

我的问题是javascript不喜欢字段名称中的#..是否有办法访问它?

my problem is that javascript does not like the # in the field name.. is there a way to access it?

推荐答案

item.description['#cdata-section']

这篇关于使用奇怪的字符访问Json字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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