0

次のjsonデータがあります。

{
  "movies": [{
  "id": "770687943",
  "title": "Harry Potter and the Deathly Hallows - Part 2",
  "year": 2011,
  "mpaa_rating": "PG-13",
   "runtime": 130,
   "critics_consensus": "Thrilling, powerfully acted, and visually dazzling, Deathly Hallows Part II brings the Harry Potter franchise to a satisfying -- and suitably magical -- conclusion.",
  "release_dates": {"theater": "2011-07-15"},
  "ratings": {
  "critics_rating": "Certified Fresh",
  "critics_score": 97,
  "audience_rating": "Upright",
  "audience_score": 93
},
"synopsis": "Harry Potter and the Deathly Hallows - Part 2, is the final adventure in the Harry Potter film series. The much-anticipated motion picture event is the second of two full-length parts. In the epic finale, the battle between the good and evil forces of the wizarding world escalates into an all-out war. The stakes have never been higher and no one is safe. But it is Harry Potter who may be called upon to make the ultimate sacrifice as he draws closer to the climactic showdown with Lord Voldemort. It all ends here. -- (C) Warner Bros",
"posters": {
  "thumbnail": "http://content8.flixster.com/movie/11/15/86/11158674_mob.jpg",
  "profile": "http://content8.flixster.com/movie/11/15/86/11158674_pro.jpg",
  "detailed": "http://content8.flixster.com/movie/11/15/86/11158674_det.jpg",
  "original": "http://content8.flixster.com/movie/11/15/86/11158674_ori.jpg"
},
"abridged_cast": [
  {
    "name": "Daniel Radcliffe",
    "characters": ["Harry Potter"]
  },
  {
    "name": "Rupert Grint",
    "characters": [
      "Ron Weasley",
      "Ron Wesley"
    ]
  },
  {
    "name": "Emma Watson",
    "characters": ["Hermione Granger"]
  },
  {
    "name": "Helena Bonham Carter",
    "characters": ["Bellatrix Lestrange"]
  },
  {
    "name": "Ralph Fiennes",
    "characters": ["Lord Voldemort"]
  }
],
"alternate_ids": {"imdb": "1201607"},
"links": {
  "self": "http://api.rottentomatoes.com/api/public/v1.0/movies/770687943.json",
  "alternate": "http://www.rottentomatoes.com/m/harry_potter_and_the_deathly_hallows_part_2/",
  "cast": "http://api.rottentomatoes.com/api/public/v1.0/movies/770687943/cast.json",
  "clips": "http://api.rottentomatoes.com/api/public/v1.0/movies/770687943/clips.json",
  "reviews": "http://api.rottentomatoes.com/api/public/v1.0/movies/770687943/reviews.json",
  "similar": "http://api.rottentomatoes.com/api/public/v1.0/movies/770687943/similar.json"
}
}],
 "links": {
  "self": "http://api.rottentomatoes.com/api/public/v1.0/lists/movies/box_office.json?limit=1&country=us",
  "alternate": "http://www.rottentomatoes.com/movie/box_office.php"
 },
"link_template":  "http://api.rottentomatoes.com/api/public/v1.0/lists/movies/box_office.json?limit={num-results}&country={country-code}"
}

上記の json 出力から必要なのは、オブジェクトimage内の. 第二。3 番目の評価、つまりオブジェクト内にあるもの。テンプレートエンジンでこれを読んでいる方法は次のとおりですposterprofiletitlecritics_scoreaudience_scoreratingunderscorejs

<% _.each(movies, function(movie) { %>
<% var imdb_id; %>
<div class="boxone">
    <% _.each(movie, function (poster) { %>
        <img class="poster" src="<%= poster.profile %>" />
    <% }); %>
    <h4><%= movie.title %></h4>
    <p>
        <span>Up vote: </span>
        <% _.each(movie, function (rating) { %>
            <%= rating.audience_score %>
        <% }); %>
    </p>

    <p>
        <span>Down vote: </span>
        <% _.each(movie, function (rating) { %>
            <%= rating.critics_score %>
        <% }); %>
    </p>

    <p>
        <% _.each(movie, function (alternate_ids) { %>
            <% imdb_id = alternate_ids.imdb; %>
            <%= imdb_id %>
        <% }); %>
        <span>ID: </span><%= imdb_id %>
        <a href="http://www.imdb.com/title/tt<% imdb_id %>">IMDB</a>
    </p>

</div>
<% }); %>

問題

私の現在のコードの問題は、オブジェクトprofile内の画像を読み取って表示したいときに、最初に関数内で使用してから、いくつかの空の img タグを作成することです。各関数内の他の 2 つについても同様です。はいの場合、上記のjsonデータを読み取るより良い方法はありますか?postereach()

4

0 に答える 0