如何将PHP中找到的特定数据返回给JSON调用

时间:2016-11-12 19:11:46

标签: php json

由于来自API的用户输入有不同的结果,我需要打印消息,表明没有特定元素的结果,并打印其中的其他元素。例如,我想说这个变量没有结果:$ model = $ jfo - > engine-> valve-> timing; 这是我目前为止的代码,这里是API的链接: http://api.edmunds.com/api/vehicle/v2/vins/1GCGG25U261243927?fmt=json&api_key=2jwwaax2sc4kuq7vg7ud79rc

<?php

//ini_set("display_errors",1);

//exit;

$datvin="";
$title="";
$posts="";
$mds="";
$model="";
if (isset($_POST['vin'])){
$datvin=trim($_POST['vin']);
$json_file = file_get_contents('http://api.edmunds.com/api/vehicle/v2/vins/'.$datvin.'?fmt=json&api_key=2jwwaax2sc4kuq7vg7ud79rc');
// convert the string to a json object
$jfo = json_decode($json_file);
if ($jfo != '' && $jfo !== null) {
// read the title value
$title = $jfo->make->name;
// copy the posts array to a php var
$posts = $jfo->make->id;
$mds = $jfo->years[0]->year;
$model = $jfo ->engine->valve->timing;


}else {

    $model="not found";
}


}


?>
 <form role="form" action="index.php" method="post">
          <div class="form-group">
              <label for="VIN" class="hidden-lg hidden-md">Enter your VIN</label>
              <input type="text" class="form-control" id="VIN" name="vin" placeholder="Enter your VIN" required="required">
          </div>

          <button type="submit" class="btn btn-primary btn-centered"><i class="fa fa-search"></i> Test VIN</button>
        </form>

        <div><?php echo $model; ?></div>

1 个答案:

答案 0 :(得分:0)

querable.Where("Packs.Equipments.Select((GenericEquipment.Id)=1)");