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

后端 未结 3 1200
面向向阳花
面向向阳花 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:46

    As you've discovered, you can't use an @ symbol in a Javascript variable name, my_json.@type is invalid.

    The good news for you is that you can access your variables as array subscripts. You would do it like this:

    my_json["@type"]
    

    Hope that helps.

提交回复
热议问题