Accessing JSON data with colon in the label

后端 未结 2 644
小蘑菇
小蘑菇 2021-01-19 22:02

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:

  • 2条回答
    •  执笔经年
      2021-01-19 22:48

      I'll assume I know the answer to my question from the comments and post what would be my response:

      Assumption

      Your JSON parses fine but your code can't access something in the resulting data structure

      Answer

      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];
      

      Addendum

      For Angular template, try

      {{i['autn:numhits']}}
      

    提交回复
    热议问题