Parsing JSON w/ @ at sign symbol in it (arobase)

后端 未结 3 1198
面向向阳花
面向向阳花 2020-11-29 08:28

My JSON object evaluates to:

{ \"@io\": IO, \"@type\": XXX }

If this variable is called my_json, how do I access the @ty

3条回答
  •  醉话见心
    2020-11-29 08:47

    Use square bracket notation with a string:

    var XXXValue = my_json['@type'];
    

    The same can be used when you have a property name in a variable. Using your same example:

    var propertyName = '@type';
    var XXXValue = my_json[propertyName];
    

提交回复
热议问题