2016-10-09 184 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