1
이 JSON 페이지에서 두 가지 속성을 성공적으로 가져 왔지만 "년"속성을 얻는 데 어려움을 겪고 있습니다. 문제는 내가 부모 요소를 놓치고 있다는 것입니다. 누군가가 올바른 방향으로 나를 가리킬 수 있다면 크게 감사 할 것입니다. 이 JSON 구조의 링크입니다 : http://api.edmunds.com/api/vehicle/v2/vins/WAUYP54B01N099265?fmt=json&api_key=XXXPHP를 사용하는 JSON에서 연도 속성 받기
당신은 여기 this eval.in
의 API의 결과를 볼 수는 코드입니다 :
<?php
$datvin="";
$title="";
$posts="";
$mds="";
// copy file content into a string var
if (isset($_POST['datvin'])){
$datvin=trim($_POST['datvin']);
$json_file = file_get_contents('http://api.edmunds.com/api/vehicle/v2/vins/'.$datvin.'?fmt=json&api_key=XXX');
// convert the string to a json object
$jfo = json_decode($json_file);
// read the title value
$title = $jfo->make->name;
// copy the posts array to a php var
$posts = $jfo->make->id;
$mds= $jfo->years->year;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="container">
<div class="header">
</div><!-- header -->
<h1 class="main_title"><?php echo $title; ?></h1>
<div class="content">
<form method="post">
<input type="text" name="datvin"><br>
<input type="submit">
</form>
<ul class="ul_json clearfix">
<?php
echo "$title<br>";
echo "$posts<br>";
echo "$mds";
?>
</ul>
</div><!-- content -->
<div class="footer">
</div><!-- footer -->
</div><!-- container -->
</body>
</html>
var_dump ($ jfo)를 사용하여 최종 배열을 보는 것이 좋습니다. 어떻게 생겼는지보기 ... – TimBrownlaw
사용자가 자신의 작전에 API 키를 남겼습니다. 구조를 보았습니다. – Styphon
그래, 그냥 이전에 그것을 확인하지만, 나는 그것을 방금 뽑아 본 적이 없다. :) 그래서 좋은 발견! – TimBrownlaw