在API中获取数据的问题

如何解决在API中获取数据的问题

遇到这个问题的人从我的api中检索数据。假设api响应是这样的: 代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form id="form" onsubmit="return false;">
        <input type="text" id="myText" value="chefbezos" />
        <button onclick="myFunction()">Try it</button>
      </form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
    <script>
         var username = document.getElementById('myText').value;
        $.getJSON({

  url : 'https://fortnite-api.com/v1/stats/br/v2?name=ninja',headers: {'Authorization': '5d661c2a-59e41e68-854c5a46-6f742ef8'},success : function(data) {
     console.log(data.data.account.name)
  }
});
         
    </script>
</body>
</html>

结果:

fortnite.html:22 Uncaught TypeError: Cannot read property 'account' of undefined
    at Object.success (fortnite.html:22)
    at c (jquery.min.js:2)
    at Object.fireWith [as resolveWith] (jquery.min.js:2)
    at l (jquery.min.js:2)
    at XMLHttpRequest.<anonymous> (jquery.min.js:2)

API响应:

{"status":200,"data":{"account":{"id":"4735ce9132924caf8a5b17789b40f79c","name":"Ninja"},"battlePass":{"level":91,"progress":57},"image":null,"stats":{"all":{"overall":{"score":3276391,"scorePerMin":34.885,"scorePerMatch":149.709,"wins":7582,"top3":3289,"top5":3504,"top6":3871,"top10":3168,"top12":4329,"top25":4004,"kills":133467,"killsPerMin":1.421,"killsPerMatch":6.099,"deaths":14303,"kd":9.331,"matches":21885,"winRate":34.645,"minutesPlayed":93920,"playersOutlived":528192,"lastModified":"2020-10-13T02:11:41Z"},"solo":{"score":703737,"scorePerMin":34.416,"scorePerMatch":95.851,"wins":2195,"top10":3116,"top25":3944,"kills":47759,"killsPerMin":2.336,"killsPerMatch":6.505,"deaths":5147,"kd":9.279,"matches":7342,"winRate":29.896,"minutesPlayed":20448,"playersOutlived":129606,"duo":{"score":1270669,"scorePerMin":32.861,"scorePerMatch":171.875,"wins":2684,"top5":3477,"top12":4293,"kills":42475,"killsPerMin":1.098,"killsPerMatch":5.745,"deaths":4709,"kd":9.02,"matches":7393,"winRate":36.305,"minutesPlayed":38668,"playersOutlived":204404,"lastModified":"2020-10-02T23:04:37Z"},"trio":{"score":47378,"scorePerMin":26.587,"scorePerMatch":301.771,"wins":24,"top3":28,"top6":53,"kills":491,"killsPerMin":0.276,"killsPerMatch":3.127,"deaths":133,"kd":3.692,"matches":157,"winRate":15.287,"minutesPlayed":1782,"playersOutlived":7930,"lastModified":"2020-10-06T19:34:56Z"},"squad":{"score":1254607,"scorePerMin":37.993,"scorePerMatch":179.409,"wins":2679,"top3":3161,"top6":3707,"kills":42742,"killsPerMin":1.294,"killsPerMatch":6.112,"deaths":4314,"kd":9.908,"matches":6993,"winRate":38.31,"minutesPlayed":33022,"playersOutlived":186252,"lastModified":"2020-10-03T00:42:42Z"},"ltm":{"score":115225,"scorePerMin":42.55,"scorePerMatch":286.629,"wins":157,"kills":3128,"killsPerMin":1.155,"killsPerMatch":7.781,"deaths":245,"kd":12.767,"matches":402,"winRate":39.055,"minutesPlayed":2708,"playersOutlived":14193,"lastModified":"2020-04-03T06:37:53Z"}},"keyboardMouse":{"overall":{"score":3264456,"scorePerMin":34.884,"scorePerMatch":149.574,"wins":7575,"top3":3287,"top5":3498,"top6":3869,"top10":3165,"top12":4318,"top25":3996,"kills":133285,"killsPerMin":1.424,"killsPerMatch":6.107,"deaths":14250,"kd":9.353,"matches":21825,"winRate":34.708,"minutesPlayed":93580,"playersOutlived":525777,"solo":{"score":699630,"scorePerMin":34.429,"scorePerMatch":95.827,"wins":2194,"top10":3113,"top25":3936,"kills":47699,"killsPerMin":2.347,"killsPerMatch":6.533,"deaths":5107,"kd":9.34,"matches":7301,"winRate":30.051,"minutesPlayed":20321,"playersOutlived":128479,"duo":{"score":1264352,"scorePerMin":32.85,"scorePerMatch":171.391,"wins":2680,"top5":3471,"top12":4282,"kills":42384,"killsPerMin":1.101,"deaths":4697,"kd":9.024,"matches":7377,"winRate":36.329,"minutesPlayed":38489,"playersOutlived":203319,"squad":{"score":1253096,"scorePerMin":37.986,"scorePerMatch":179.27,"wins":2677,"top3":3159,"top6":3705,"kills":42711,"killsPerMin":1.295,"killsPerMatch":6.11,"deaths":4313,"kd":9.903,"matches":6990,"winRate":38.298,"minutesPlayed":32988,"playersOutlived":186049,"ltm":{"score":114074,"scorePerMin":42.837,"scorePerMatch":285.9,"kills":3060,"killsPerMin":1.149,"killsPerMatch":7.669,"deaths":242,"kd":12.645,"matches":399,"winRate":39.348,"minutesPlayed":2663,"playersOutlived":14084,"lastModified":"2020-02-17T20:41:05Z"}},"gamepad":{"overall":{"score":11719,"scorePerMin":35.948,"scorePerMatch":285.829,"wins":7,"top3":2,"top5":6,"top6":2,"top10":3,"top12":11,"top25":5,"kills":178,"killsPerMin":0.546,"killsPerMatch":4.341,"deaths":34,"kd":5.235,"matches":41,"winRate":17.073,"minutesPlayed":326,"playersOutlived":2261,"lastModified":"2020-07-08T17:15:40Z"},"solo":{"score":3891,"scorePerMin":34.434,"scorePerMatch":176.864,"wins":1,"kills":56,"killsPerMin":0.496,"killsPerMatch":2.545,"deaths":21,"kd":2.667,"matches":22,"winRate":4.545,"minutesPlayed":113,"playersOutlived":973,"duo":{"score":6317,"scorePerMin":35.291,"scorePerMatch":394.812,"wins":4,"kills":91,"killsPerMin":0.508,"killsPerMatch":5.688,"deaths":12,"kd":7.583,"matches":16,"winRate":25,"minutesPlayed":179,"playersOutlived":1085,"lastModified":"2020-04-23T22:16:27Z"},"trio":null,"squad":{"score":1511,"scorePerMin":44.441,"scorePerMatch":503.667,"wins":2,"kills":31,"killsPerMin":0.912,"killsPerMatch":10.333,"deaths":1,"kd":31,"matches":3,"winRate":66.667,"minutesPlayed":34,"playersOutlived":203,"lastModified":"2019-06-04T23:55:25Z"},"ltm":{"score":1151,"scorePerMin":25.578,"scorePerMatch":383.667,"wins":0,"kills":68,"killsPerMin":1.511,"killsPerMatch":22.667,"deaths":3,"kd":22.667,"winRate":0,"minutesPlayed":45,"playersOutlived":109,"touch":{"overall":{"score":216,"scorePerMin":15.429,"scorePerMatch":11.368,"top3":0,"top5":0,"top6":0,"top10":0,"top12":0,"top25":3,"kills":4,"killsPerMin":0.286,"killsPerMatch":0.211,"deaths":19,"kd":0.211,"matches":19,"minutesPlayed":14,"playersOutlived":154,"lastModified":"2018-12-24T03:00:08Z"},"solo":{"score":216,"duo":null,"squad":null,"ltm":null}}}}

用户名的数据不应该为data.data.account.name吗?当我放入它时,它不会接收任何数据。上方的数据链接正确吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res