如何控制json条目时获取它

how to control json entries when fetch it

本文关键字:获取 json 何控制 控制      更新时间:2023-09-26

我的代码显示所有json文件条目的图像和标题和摘要所有我需要显示的图像,标题和摘要到第一个条目,并将显示标题到其他条目。

请建议。

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
<script>
$(function() {
var entries = [];
var dmJSON = "http://localhost:8080/Newfolder/test.json";
$.getJSON( dmJSON, function(data) {
   $.each(data.entries, function(i, f) {
      var tblRow = "<tr>" + "<td>" + f.image + "</td>" + "<td>" + f.title + "</td>" + "<td>" + f.summary + "</td>" + "</tr>"
       $(tblRow).appendTo("#entrydata tbody");
 });
});
});
</script>
</head>
<body>
<div class="wrapper">
<div class="profile">
<table id= "entrydata" border="1">
<thead>
        <th>ID</th>
        <th>UserName</th>
        <th>Message</th>
    <th>Location</th>
        <th>Time</th>
    </thead>
  <tbody>
   </tbody>
</table>
</div>
</div>
</body>
</html>

请注意我更新的代码:

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
<script>
$(function() {
var items = [];
var dmJSON = "http://localhost:8080/Newfolder/realaljazeera.json";
$.getJSON( dmJSON, function(data) {
   $.each(data.entries, function(i, f) {
    if (i == 0) {
        var tblRow = "<tr>" + "<td>" + "<img src="+f.Image3+"/>" + "</td>" + "<td>" + f.Title + "</td>" + "<td>" + f.Summary + "</td>" + "</tr>"
    } else {
        var tblRow = "<tr>" + "<td>" + f.Title + "</td>" + "</tr>"
    }
    $(tblRow).appendTo("#entrydata tbody");
});
});
});
</script>
</head>
<body>
<div class="wrapper">
<div class="profile">
<table id= "entrydata" border="2" style="width:680px;">
<tbody>
</tbody>
</table>
</div>
</div>
</body>
</html>
$.each(data.entries, function(i, f) {
    if (i == 0) {
        var tblRow = // what you want for first entry
    } else {
        var tblRow = // what you want for other entries
    }
    $(tblRow).appendTo("#entrydata tbody");
});