2016-10-09 189 views
1

嗨链接我试图找出如何让这种类型的请求的响应链接的价值:获取href的值的Json与HAL

{ 
    "_links" : { 
      "self" : {"href" : "https://link.net/someInfo" }, 

      "profile" : {"href" : "https://link.net"}, 

    ==>  "https://link.net/item1" : {"href" : "https://thelinkIwanttohave.net"}, 

      "https://link.net/item2" : {"href" : "https://link.net"}, 
    }, 
    "reference" : "723bb02f-8e24-11e6-9184-000000000000" 
} 

在此之后(http://blog.stateless.co/post/13296666138/json-linking-with-hal) 如果我想获取自我href值。我可以得到它通过:

json._links.self.href 

但我怎么能得到https://link.net/item1 href值。 如果键入:

json._links.https://link.net/item1.href 

我得到了一个未捕获的SyntaxError:意外的标记。我找不到这个例子。

回答

0

看一看property accessors,您可以通过以下两种方式访问​​JavaScript属性:

object.property 
object["property"] 

所以你的情况尝试:

json._links['https://link.net/item1'].href