1

Can we add images to the Json reponse ? I have made a custome JSON reponse but want to add image on some conditions like if flight in array is "AI" show image "http://sss.com/images/images/AI.png"

Any tutorial of idea will help me in this.

This is the response

$obj = json_decode($json);
foreach ($obj->flightStatuses as $flightstatus) {
    echo $flightstatus->carrierFsCode,' ', $flightstatus->flightNumber,"<br>";
     if ($flightstatus->carrierFsCode=='G8')
            { echo "Goair<br>";} elseif ($flightstatus->carrierFsCode== 'SG') {echo "Spicejet<br>";}elseif ($flightstatus->carrierFsCode== '9W') {echo "Jetairways<br>";}
            elseif ($flightstatus->carrierFsCode== 'S2') {echo "JetConnect<br>";}elseif ($flightstatus->carrierFsCode== '6E') {echo "Indigo<br>";}
            elseif ($flightstatus->carrierFsCode== 'AI') {echo "Air India<br>";};

How can I add image in this ? thanks in advance,

4

4 回答 4

8

JSON 可以包含字符串。字符串可以包括 Base64 编码的图像二进制文件或指向图像的 URI。

{
    "base64": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAZQTFRFAAD/////e9yZLAAAAAF0Uk5Tf4BctMsAAAABYktHRAH/Ai3eAAAACklEQVQI12NgAAAAAgAB4iG8MwAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxMy0wNC0yM1QxMTowMDowOSswMTowMDogwR0AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTMtMDQtMjNUMTE6MDA6MDkrMDE6MDBLfXmhAAAAAElFTkSuQmCC",
    "url": "http://example.com/blue_0.5_pixel.png"
}

(然而,在这个例子中,同时拥有两者是多余的)。

于 2013-04-23T09:59:20.857 回答
0

当然可以,如果您愿意,可以使用 json 中的图像 URL,甚至可以使用完整的图像字符串。

于 2013-04-23T09:59:11.833 回答
0

根据您对问题的修改……</p>

你似乎想多了。您只想输出(使用HTML,而不是 JSON)变量中的一段数据。

<img src="http://sss.com/images/images/<?php
    echo htmlspecialchars($flightstatus->carrierFsCode);
?>.png" alt="">
于 2013-04-23T10:28:20.160 回答
0

您必须将图像文件中的字节读入 abyte[]并将该对象放入您的JSONObject.

于 2013-04-23T10:01:35.363 回答