2 回答

TA貢獻1864條經(jīng)驗 獲得超6個贊
我的猜測是,您可能希望編寫一些帶有if語句的for 循環(huán)來根據(jù)需要顯示數(shù)據(jù):
測試
$json = file_get_contents('https://api.mymemory.translated.net/get?q=Hello%20World!&langpair=en|it');
$data = json_decode($json, true);
if (isset($data["responseData"])) {
foreach ($data["responseData"] as $key => $value) {
// This if is to only display the translatedText value //
if ($key == 'translatedText' && !is_null($value)) {
$html = $value;
} else {
continue;
}
}
} else {
echo "Something is not right!";
}
echo $html;
輸出
Ciao Mondo!
<?php
$html = '
<!DOCTYPE html>
<html>
<head>
<title>read JSON from URL</title>
</head>
<body>
';
$json = file_get_contents('https://api.mymemory.translated.net/get?q=Hello%20World!&langpair=en|it');
$data = json_decode($json, true);
foreach ($data["responseData"] as $key => $value) {
// This if is to only display the translatedText value //
if ($key == 'translatedText' && !is_null($value)) {
$html .= '<p>' . $value . '</p>';
} else {
continue;
}
}
$html .= '
</body>
</html>';
echo $html;
?>
輸出
<!DOCTYPE html>
<html>
<head>
<title>read JSON from URL</title>
</head>
<body>
<p>Ciao Mondo!</p>
</body>

TA貢獻1757條經(jīng)驗 獲得超8個贊
經(jīng)過多次研究,我以這種方式工作:
$json = file_get_contents('https://api.mymemory.translated.net/get?q=Map&langpair=en|it');
$obj = json_decode($json);
echo $obj->responseData->translatedText;
謝謝你們。
- 2 回答
- 0 關(guān)注
- 154 瀏覽
添加回答
舉報