我试图访问一个字段的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.