Reputation:
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,
Upvotes: 1
Views: 3031
Reputation: 943142
Based on the edits to your question…
You appear to be overthinking things. You just want to output (using HTML, not JSON) a piece of data you have in a variable.
<img src="http://sss.com/images/images/<?php
echo htmlspecialchars($flightstatus->carrierFsCode);
?>.png" alt="">
Upvotes: 0
Reputation: 10555
You have to read the bytes from the image File into a byte[]
and put that object into your JSONObject
.
Upvotes: 0
Reputation: 943142
JSON can include strings. Strings can include Base64 encoded binaries of images or URIs pointing to images.
{
"base64": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAZQTFRFAAD/////e9yZLAAAAAF0Uk5Tf4BctMsAAAABYktHRAH/Ai3eAAAACklEQVQI12NgAAAAAgAB4iG8MwAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxMy0wNC0yM1QxMTowMDowOSswMTowMDogwR0AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTMtMDQtMjNUMTE6MDA6MDkrMDE6MDBLfXmhAAAAAElFTkSuQmCC",
"url": "http://example.com/blue_0.5_pixel.png"
}
(Having both, as in this example, is, however, redundant).
Upvotes: 8
Reputation: 9034
Sure you can, you can use the image URL in json or even the full image string if you want to.
Upvotes: 0