与结肠癌访问JSON数据在标签 [英] Accessing JSON data with colon in the label
问题描述
我有在我发现难以进入的角度与下面code标签(见responsedata)冒号JSON数据:
I have json data with a colon in the label (see responsedata) which I'm finding difficult to access in Angular with the following code:
<li ng-repeat="i in items.autnresponse.responsedata | searchFor:searchString"> <p>{{i.autn:numhits}}</p> </li>
我不断收到这样的错误:
I keep getting an error like this:
错误:[$解析:语法]语法错误:令牌:在恩pression的7列一个意外标记[i.autn:numhits]在开始[:numhits ]
。
JSON数据摘录:
"autnresponse": {
"action": {
"$": "QUERY"
},
"response": {
"$": "SUCCESS"
},
"responsedata": {
"autn:numhits": {
"$": "92"
},
"autn:totalhits": {
"$": "92"
},
"autn:totaldbdocs": {
"$": "188"
},
"autn:totaldbsecs": {
"$": "188"
},
有谁知道解决的办法?
Does anybody know a way around this?
推荐答案
我假设我知道从评论回答我的问题,并张贴这将是我的回应:
I'll assume I know the answer to my question from the comments and post what would be my response:
假设
您JSON解析不错,但你的code中所得到的数据结构不能访问的东西。
Your JSON parses fine but your code can't access something in the resulting data structure
答
使用方括号,用字符串:
Use square bracket notation with a string:
var x = i['autn:numhits'];
当你有一个变量属性名称同样可以使用。使用相同的例子:
The same can be used when you have a property name in a variable. Using your same example:
var propertyName = 'autn:numhits';
var x = i[propertyName];
附录
有关角模板,尝试
{{i['autn:numhits']}}
这篇关于与结肠癌访问JSON数据在标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!