如何引用包含分号的对象


How to reference an object that has a semi colon in

我正在使用带有WordPress Rest API的AngularJS。我正在发出一个返回对象的 get 请求。要获得特色图像,我必须使用"?embed"参数,该参数给出了另一个名为_embedded的对象。

问题是我想要的_embedded里面的对象叫做wp:featuredmedia。如果我在角度中这样引用它,我会得到语法错误。

这是我的代码

$http.get(queries[0], {'cache': true}).
    then(function(response) {
        $scope.careers_title = strip(response.data.title.rendered);
        $scope.careers_content = strip(response.data.content.rendered);
        $scope.careers_feature_image = strip(response.data.featured_media);
        console.log(response.data._embedded);
    });

控制台.log返回此

Object {author: Array[1], wp:featuredmedia: Array[1], wp:term: Array[2]}author: Array[1]wp:featuredmedia: Array[1]0: Object_links: Objectalt_text: ""author: 1date: "2016-04-25T09:33:52"id: 46link: "http://localhost:8888/rubis/wordpress/energy-efficiency/tp-roundall/"media_details: Objectmedia_type: "image"mime_type: "image/png"slug: "tp-roundall"source_url: "http://localhost:8888/rubis/wordpress/wp-content/uploads/2016/04/tp-roundall.png"title: Objecttype: "attachment"__proto__: Objectlength: 1__proto__: Array[0]wp:term: Array[2]__proto__: Object
事实上,

你不能写:

response.data._embedded.wp:featuredmedia

这是禁止的属性名称。但是,接受任何字符串,因此您可以通过以下方式访问它:

response.data._embedded['wp:featuredmedia']

你好,除了前面的例子,如果你

使用谷歌检查,你可以只查看JSON响应并复制JSONSON路径

data._embedded["wp:featuredmedia"]["0"].media_details.size.medium

 [enter image description here][1]