【问题标题】:how to access to response data index by javascript如何通过javascript访问响应数据索引
【发布时间】:2020-04-23 15:22:14
【问题描述】:

你好朋友,我如何使用 javascript 从数据响应中访问数据索引。这是我的代码: HTML

<label id="user">USER</label>

这里是javascript

this.$store.dispatch('Login',this.value_login)
  .then(response => {
    if(response!='') {
      this.login_result = new Array();
      this.login_result = response;
      document.getElementById('user').innerHTML= this.login_result.firstname
    }
   });

这是我从响应中得到的数据

enter image description here

感谢您的帮助

【问题讨论】:

  • 数据索引是什么意思?您还可以分享您对该电话的回复吗?注意 this.login_result = new Array(); 是多余的,因为它被以下内容覆盖:this.login_result = response;
  • 好的,我已经编辑了我的问题并将数据图片添加到我的问题中
  • 复制粘贴数据而不是图像会更好(下次) - 但也感谢您。
  • 看到您的响应的 pass 和 word 之间的回车(换行符)字符了吗?这会破坏 json
  • 好的,这是复制过去:[{"id":1,"firstname":"Neng","lastname":"vang","email":"nengvang@gmail.com", "密码":"1234"}]

标签: javascript html css node.js vue.js


【解决方案1】:

鉴于 API 调用的响应是根据屏幕截图和评论的数组:

[
  {
  "id":1,
  "firstname":"Neng",
  "lastname":"vang",
  "email":"nengvang@gmail.com",
  "password":"1234"
  }
]

问题是要求检索名字和姓氏,因此解决方案是在结果数组上使用索引 0,如下所示:

this.login_result[0].firstnamethis.login_result[0].lastname

【讨论】:

  • 大家好,现在一切正常,感谢您的帮助
猜你喜欢
  • 1970-01-01
  • 2014-01-08
  • 2019-01-11
  • 2020-06-30
  • 1970-01-01
  • 2018-12-09
  • 2019-07-23
  • 1970-01-01
  • 2011-12-24
相关资源
最近更新 更多