在json中获取对象的问题。Java脚本

弗朗西斯科·莱莫斯

我正在为学校做一个项目,这是一个显示所有电影信息的网站。我正在这样做的API,电影数据库,HTML CSS和JavaScript

  1. 现在我正试图让按钮带我去看某些类型的电影

这是我在html上的代码

<div class="wrapper-structure-esqueleto">

            <img class="logo" src="img/logo.png" alt="logo">

            <div class="first-section-hiperlinks">

                <h3>DISCOVER</h3>
                
                <a class="border-initial">
                    <p> aaa </p>
                </a>
                <a class="border">
                    <p> aaa </p>
                </a>
                <a class="border">
                    <p> aaa </p>
                </a>

            </div>
            <div class="second-section-hiperlinks">

                <h3>GENRES</h3>
            
                    <a href="#" class="border" id="doc-genre">
                        <p> genre-name </p>
                    </a>

            </div>

            <div class="footer">
                <div class="credits">
                    <p>Made by <strong>Francisco Lemos</strong></p>
                </div>
                <img src="img/poweredby.png">
            </div>

        </div>

        <!-- doc -->

        <div class="wrapper-structure">

            <img class="logo" src="img/logo.png" alt="logo">

            <div class="first-section-hiperlinks">

                <h3>DISCOVER</h3>
                
                <a class="border-initial">
                    <p> aaa </p>
                </a>
                <a class="border">
                    <p> aaa </p>
                </a>
                <a class="border">
                    <p> aaa </p>
                </a>

            </div>
            <div class="second-section-hiperlinks">

                <h3>GENRES</h3>
            
                <div class="wrapper" id="find-genres">
        
                </div>

            </div>

            <div class="footer">
                <div class="credits">
                    <p>Made by <strong>Francisco Lemos</strong></p>
                </div>
                <img src="img/poweredby.png">
            </div>

        </div>

这是我的js代码

function getFindGenres(){

  document.querySelector('.wrapper').innerHTML = "";

  axios( {
      method: 'get',
      url: 'https://api.themoviedb.org/3/discover/movie?api_key=(API-KEY)&page=1&with_genres=28'
    })
    .then(function (response) {
      response.data.with_genres.forEach(with_genres => {
        let htmlFindGenres = document.querySelector('.wrapper').outerHTML;
        htmlFindGenres = htmlFindGenres.replace('#find-genres',genre_ids);
        var d4 = document.querySelector('.wrapper');
        d4.insertAdjacentHTML('beforeend', htmlFindGenres);
      })
    })
}

在这条线上给我错误

 response.data.with_genres.forEach(with_genres => {

而且我不知道该放什么,有人可以帮我吗?

https://api.themoviedb.org/3/discover/movie?api_key=(API-KEY)&page=1&with_genres=28的图片

返回的JSON的小样本

{
  "page": 1,
  "results": [
    {
      "adult": false,
      "backdrop_path": "/srYya1Z1197Au4jUyAktDe3avyA.jpg",
      "genre_ids": [14, 28, 12],
      "id": 464052,
      "original_language": "en",
      "original_title": "Wonder Woman 1984",
      "overview": "Wonder Woman comes into conflict with the Soviet Union during the Cold War in the 1980s and finds a formidable foe by the name of the Cheetah.",
      "popularity": 1927.057,
      "poster_path": "/8UlWHLMPgZm9bx6QYh®NFOq67Tz.jpg",
      "release_date": "2020-12-16",
      "title": "Wonder Woman 1984",
      "video": false,
      "vote_average": 6.9,
      "vote_count": 3689
    },
    {
      "adult": false,
      "backdrop_path": "/6TPZSJ060EXeelx101VIATOj9Ry.jpg",
      "genre_ids": [28, 80, 53],
      "id": 587996,
      "original_language": "es",
      "original_title": "Bajocero",
      "overview": "When a prisoner transfer van is attacked, the cop in charge must fight those inside and outside while dealing with a silent foe: the icy temperatures.",
      "popularity": 1358.629,
      "poster_path": "/dwSnSAGTfc8U27bwsy 2RfWZsoBs.jpg",
      "release_date": "2021-01-29",
      "title": "Below Zero",
      "video": false,
      "vote_average": 6.4,
      "vote_count": 317
    },
    {
      "adult": false,
      "backdrop_path": "/10SdUkGQmbA15JQ3QoHqBZUbZhc.jpg",
      "genre_ids": [53, 28, 878],
      "id": 775996,
      "original language": "en",
      "original_title": "Outside the Wire",
      "overview": "In the near future, a drone pilot is sent into a deadly militarized zone and must work with an android officer to locate a doomsday device.",
      "popularity": 1230.86,
      "poster_path": "/6XYLiMxHAaCsoyrVo38LBWMw2p8.jpg",
      "release_date": "2021-01-15",
      "title": "Outside the Wire",
      "video": false,
      "vote_average": 6.5,
      "vote_count": 703
    }
  ],
  "total_pages": 500,
  "total_results": 10000
}

TOP_PTBEV

有效载荷没有属性with_genres,对吗?

因此,这应该可行,尚未进行测试,所以请告诉我:

function getFindGenres(){

  document.querySelector('.wrapper').innerHTML = "";

  axios( {
      method: 'get',
      url: 'https://api.themoviedb.org/3/discover/movie?api_key=(API-KEY)&page=1&with_genres=28'
    })
    .then(function (response) {
      response.data.results.forEach(result => {
        let htmlFindGenres = document.querySelector('.wrapper').outerHTML;
        htmlFindGenres = htmlFindGenres.replace('#find-genres',result.genre_ids);
        var d4 = document.querySelector('.wrapper');
        d4.insertAdjacentHTML('beforeend', htmlFindGenres);
      })
    }) }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

从Java脚本/类型脚本中的对象数组获取属性数组

来自分类Dev

在Java中的Json对象中获取Json对象

来自分类Dev

获取对象JSON Java Android中的所有对象

来自分类Dev

Map中的Json对象,如何在java中获取它?

来自分类Dev

在Shell脚本中获取$ PWD的问题

来自分类Dev

Java脚本中的对象期望

来自分类Dev

从URL获取JSON对象与PHP问题

来自分类Dev

从URL获取JSON对象与PHP问题

来自分类Dev

在反应中获取Json的问题

来自分类Dev

在 Blender python 脚本中获取对象数组

来自分类Dev

Java-如何获取JSON数组中的对象值?

来自分类Dev

如何通过Java中的值之一获取JSON对象?

来自分类Dev

如何在Java中获取JSON对象的ID

来自分类Dev

如何通过Java中的值之一获取JSON对象?

来自分类Dev

如何在Java中获取JSON对象的ID

来自分类Dev

在JSON Flutter中获取对象

来自分类Dev

在 Clojure 中获取 JSON 对象

来自分类Dev

在 jquery 中获取对象值的问题

来自分类Dev

从本地文件获取对象中的数据的问题

来自分类Dev

在Javascript中获取对象值的问题

来自分类Dev

PL / JSON在json对象中获取json

来自分类Dev

在Android的PHP脚本中接收JSON对象

来自分类Dev

在php脚本中传递的JSON对象

来自分类Dev

从列表中获取对象Java

来自分类Dev

在java脚本中从json获取键的值(将键名存储在变量中并使用它)

来自分类Dev

如何从json文件中获取json对象

来自分类Dev

如何使用Titanium Studio更新Java脚本中的现有json对象

来自分类Dev

如何在具有JSON字符串的Java脚本对象中访问特定的键值对

来自分类Dev

如何在具有JSON字符串的Java脚本对象中访问特定的键值对