我正在研究REST API,我有一个有很多值的JSON文件。我想检查一个特定的类别,当我找到该类别时,循环将中断,内容将显示该特定类别。这是我的代码:
<html>
<head>
<meta charset="UTF-8">
<title>SuperDeal.com Baap of all deals</title>
<script src="https://ajax.googleapis.com/…/li…/jquery/1.9.1/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script> <!-- Boostarp -->
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" media="all" />
<!-- Boostrap -->
<link rel="stylesheet" href="bootstrap/css/custom.css" media="all" />
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!--header section -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">SuperDeal.com </a>
</div>
<!-- menu section -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="# ">Home</a></li>
<li><a href="# ">Register and win </a></li>
<li><a href="#">Conatct Us </a></li>
</ul>
</div>
</div>
</nav>
<?php
$ch = curl_init("http://tools.vcommission.com/api/coupons.php…"); // add your url which contains json file
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
curl_close($ch);
$json = json_decode($content, true);
//print_R($json);
$count=count($json);
echo'<table class="table"><th>BlueStone Offers</th><th>Link</th>';
for($i=0;$i<$count;$i++)
{
if ($json[$i]['offer_name']=='Bluestone.com CPS - India'){
echo'<tr><td>'.$json[$i]['offer_name'].'</td>
<td>'.$json[$i]['coupon_title'].'</td>
<td>'.$json[$i]['coupon_code'].'</td>
<td bgcolor="yellow"><a href='.$json[$i]['link'].'> Grap The Deal </a></td>
</tr>';
echo'</table>';
}
break;
}
?>
<?php
echo substr("Koovs.com CPS - India",6);
?>
</body>
</html>
...我正在尝试使用JSON响应中包含的相关条目填充“Bluestone Offers”HTML表。我正在检查offer_name
字段中的特定字符串值(“Bluestone.com CPS - India”,如上所述)。