选择键中带冒号的JSON对象 [英] Selecting a JSON object with a colon in the key

查看:155
本文介绍了选择键中带冒号的JSON对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用发布JSON响应的第三方工具。它工作得很好,但我需要使用的一个键有一个冒号,我不知道如何在JavaScript中选择这个对象。

I'm using a third party tool that POSTs a JSON response. It works great, but one of the keys I need to use has a colon in it and I have no idea how to select this object in JavaScript.

例如:

{
  "photo": {
    "reg": {
      "id": 50
    },
    "thumb": {
      "id": 51
    },
    ":original": {
      "id": 53"
    }
  }
}

如何选择 photo.:original.id ?当我离开冒号时出现语法错误,当我尝试删除冒号时,未定义冒号。

How do I select photo.:original.id? I get syntax errors when I leave the colon in, and undefined when I try dropping the colon.

推荐答案

这很简单:

photo[':original'].id

点/括号表示法

Dot/bracket notation

这篇关于选择键中带冒号的JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆