如何从 API (json) 中调用参数 html

How to call parameters from an API (json) in html

我创建了my own API,想知道如何调用参数? 我一直在尝试使用以下代码调用 "type" 参数,但它未定义...即使我只记录 "json"...

,控制台中也没有显示任何内容

谁能告诉我我哪里做错了吗?

非常感谢!!! :))) xxx

  <canvas id="myCanvas"> </canvas>
  <script type="text/javascript" src="js/jQuery.js"></script>
  <script type="text/javascript">

   var canvas = document.getElementById("myCanvas");
   var ctx = canvas.getContext("2d");
   ctx.canvas.width = window.innerWidth;
   ctx.canvas.height = window.innerHeight;

   $(document).ready(function(){  

   var ctx = canvas.getContext("2d");

   ctx.beginPath();
    ctx.fillStyle = "rgb(255,255,255)";
    ctx.fillRect(0,0,canvas.width, canvas.height);

    var url = "https://sheetsu.com/apis/f924526c"; 


   $.getJSON(url,function(json){
   
                                console.log(json);

    var type = json.type;
    $('type').append(type);
    console.log(type);

   });
  });

  </script>

查看您从服务器获得的 JSON 数据的一部分:

{
  "status": 200,
  "success": true,
  "result": [
    {
      "number": "0",
      "URL random digit1": "1",
      "URL random digit2": "8",
      "id": "1a8",
      "name": "user1",
      "type": "mf",
      "url": "http://test.com/customised_url_1a8",
      "message": "bonjour user1"
    },
....

据此,您应该按以下方式访问第 0 个元素的 "type":

json.result[0].type

请注意,您的 json 在接收时已转换为 JS 对象。您应该按照对象的方案访问它的任何 属性。