第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何使用php解碼顯示來(lái)自json url的數(shù)據(jù)?

如何使用php解碼顯示來(lái)自json url的數(shù)據(jù)?

PHP
手掌心 2021-11-19 15:18:20
我無(wú)法使用 php json 解碼顯示來(lái)自這個(gè) url 的數(shù)據(jù):https : //api.mymemory.translated.net/get? q = Hello%20World! & langpair = en|it這是數(shù)據(jù)提供者:https : //mymemory.translated.net/doc/spec.php謝謝。我想要的是設(shè)置一個(gè)表單來(lái)提交單詞并從他們的 API 中獲取翻譯。這是我的代碼示例:<?php$json = file_get_contents('https://api.mymemory.translated.net/get?q=Hello%20World!&langpair=en|it');// parse the JSON$data = json_decode($json);// show the translationecho $data;?>
查看完整描述

2 回答

?
慕尼黑的夜晚無(wú)繁華

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超6個(gè)贊

我的猜測(cè)是,您可能希望編寫(xiě)一些帶有if語(yǔ)句的for 循環(huán)來(lái)根據(jù)需要顯示數(shù)據(jù):


測(cè)試

$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>


查看完整回答
反對(duì) 回復(fù) 2021-11-19
?
陪伴而非守候

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超8個(gè)贊

經(jīng)過(guò)多次研究,我以這種方式工作:


$json = file_get_contents('https://api.mymemory.translated.net/get?q=Map&langpair=en|it');  

$obj = json_decode($json);   

echo $obj->responseData->translatedText;

謝謝你們。


查看完整回答
反對(duì) 回復(fù) 2021-11-19
  • 2 回答
  • 0 關(guān)注
  • 168 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)