Jquery 如何读取和显示json数据

Jquery 如何读取和显示json数据,jquery,json,Jquery,Json,我有以下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, Dea

我有以下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
,它位于
poster
对象
profile
中。第二个
标题
。第三级评级,即
评论家评分
观众评分
,位于
评级
对象内。我用
下划线js
模板引擎阅读本文的方式如下

<% _.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>
<% }); %>

" />

追加表决:

否决票:

身份证件:

问题


我当前代码的问题是,当我想在
poster
对象中阅读和显示
profile
图像时,我会在
each()中使用第一个
函数,然后它会创建几个空的img标记。每个函数中的其他两个标记也是如此。如果是,有没有更好的方法读取上面的json数据?方法是什么?

有人可以帮忙吗?呈现的HTML是什么样子的?