JSON - Access字段命名为'*'星号 [英] JSON - Access field named '*' asterisk

查看:176
本文介绍了JSON - Access字段命名为'*'星号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图访​​问一个字段的JSON对象在JavaScript中有关键'*'。 该jsonstring看起来是这样的:

  {解析:
 {文本:
  {*:文字我想访问}
 }
}
 

试图访问myObject.parse.text。*不工作,也不做myObject.parse.text [0]。 我已经寻找了一个小时了,但还没有发现任何暗示星号具有特殊的意义。 如果我只是遍历整个树,使字符串比较一拉如果(关键==*)我能得到我想要检索的文本,但我想直接进入这一领域。 请问有没有办法进入现场?

解决方案

  json.parse.text [*]
 

有关对象成员令人讨厌的名字。

I am trying to access a field in a json object in javascript which has the key '*'. The jsonstring looks like this:

{"parse":
 {"text":
  {"*":"text i want to access"}
 }
}

Trying to access myObject.parse.text.* does not work, neither does myObject.parse.text[0]. I have searched for an hour now, but havent found any hint that the asterisk has a special meaning. If I just traverse the complete tree and make String comparison a la 'if (key == "*")' I can get the text I want to retrieve, but I would like to directly access this field. Is there no way to access the field ?

解决方案

json.parse.text["*"]

Yucky name for an object member.

这篇关于JSON - Access字段命名为'*'星号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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