Api平台-Hydra-使用javascript访问Hydra:member

Api平台-Hydra-使用javascript访问Hydra:member,javascript,Javascript,我遇到了我无法解决的问题。我需要用javascript打印响应对象,但我不知道怎么做。我的回答是这样的: { "@context": "/contexts/Client", "@id": "/clients", "@type": "hydra:Collection", "hydra:member": [ { "@id": "/clients/1", "@type": "Client", "uuid": "e3rer445",

我遇到了我无法解决的问题。我需要用javascript打印响应对象,但我不知道怎么做。我的回答是这样的:

{
  "@context": "/contexts/Client",
  "@id": "/clients",
  "@type": "hydra:Collection",
  "hydra:member": [
    {
      "@id": "/clients/1",
      "@type": "Client",
      "uuid": "e3rer445",
      "number": " 0483",
      "name": "Tom Beringer",
      "adresses": [
      {
          "@id": "/client_addresses/1",
          "@type": "http://schema.org/Thing",
          "address": {
              "@id": "/addresses/1",
              "@type": "http://schema.org/Thing",
              "address": "Postbus 1d425"
          }
      },
  ]
},
现在我需要打印所有客户详细信息的结果,所以当我这样做时:

axios.get('/clients')
      .then(res => {
      this.users = res.data['hydra:member']
  })
我成功地打印出了姓名、号码,但当我尝试打印出地址时,我得到了。结果:

<td><span>[
  {
    "@id": "/client_addresses/3",
    "@type": "http://schema.org/Thing",
        "address": {
        "@id": "/addresses/3",
        "@type": "http://schema.org/Thing",
        "address": "niet meer gebruiken"
     }
  } 
</span></td>
但我需要的只是这个地址:niet meer gebruiken
可以这样做吗?

您是否尝试过这样访问该属性

res.data['hydra:member']['addresses][0]['address']['address']
如果addresses数组中嵌套了多个address对象,则可能需要对其进行迭代。

是的,这是可能的

试试这个:

res.data['hydra:member'][0]['adresses'][0]['address']['address']

如果您只嵌套了一个地址对象,这将很好地工作。如果你有更多的对象在里面,你应该迭代地址数组

这将是/包含您的地址数组:

 res.data['hydra:member'][0]['adresses']

只需添加一个配置默认值

/main.js

common['Accept']='application/json'; put['Content-Type']='application/json'; get['Content-Type']='application/json'; post['Content-Type']='application/json'; delete['Content-Type']='application/json'; Vue.prototype.$http=axios; 为什么不使用解析Hydra API文档?
 res.data['hydra:member'][0]['adresses']