JSON decode not decoding correctly php - php

I have a PHP function that talks to another API for real-time train information to get data from it. It makes the call and parses the XML data to JSON but when there is only one train in the station it will come out as an object and not an array. How can I make it convert everything to an array even if there is only one train coming.
public function getStationsByName(Request $request)
{
try {
$stationName = $request->input('id');
$url = "http://api.irishrail.ie//realtime/realtime.asmx/getStationDataByNameXML?StationDesc=";
$url .= $stationName;
$res['status'] = true;
$res['message'] = 'Success';
$ir = xmlparser::Parse($url);
$res ['results'] = json_decode($ir, TRUE);
$res['num_rows'] = count($res['results']);
return response($res, 200);
} catch (\Illuminate\Database\QueryException $ex) {
$res['status'] = false;
$res['message'] = $ex->getMessage();
return response($res, 500);
}
}
This is what the data looks like with more than one train arriving at the station
And this is where there is only one arriving

You can check it by your self,
if(false !== ($result = json_decode($ir, TRUE))){
if(isset($result["objStationData"]["Servertime"])){
$objStationDatas = [$result["objStationData"]];
}else{
$objStationDatas = $result["objStationData"];
}
}

before convert JSON into array you can check if the parsed XML is an array or an object. You have to do that on your objStationData the code below is just an example
if(!is_array($ir){
$res ['results'] = json_decode($ir, TRUE);
}else{
$res ['results'] = $ir;
}
or
if(is_object($ir){
$res ['results'] = json_decode($ir, TRUE);
}else{
$res ['results'] = $ir;
}

Related

How can i modify my array code to complete even if a value does not exist in the array?

I am modifying some code i had written for my by a developer who is no longer working with us, essentially the code pulls data from a web service and parses to an array, it then looks for keys within the array and publishes associated values to an HTML table, it all works fine when each of the entries exists in the data however the point of modifying the code if to return a generic value ("not submitted") if the value is not found in the array.
background info is helpful so the use case is:
Array is made up of the sales team, they each login to a website and submit their sales totals for the day, we interrogate the web service to return the data via a SOAP call which pulls the data into the code. The data is parsed and the values are represented in a table on a web page.
If a single sales team member does not submit data then the code fails to return any data.
I've been googling and hitting my pluralsight account to learn as much as i can about how this is done but i'm falling short.
class SalesResponseFactory
{
private $date;
//private $keyArray = ['KE', 'JY', 'OR', 'KR', 'SY', 'DB'];
public $responseData = [];
function __construct($date)
{
libxml_use_internal_errors(true);
$this->date = $date;
}
private function getResponseData($date)
{
....
}
private function parserToArray($data)
{
$data = substr($data, strpos($data, "<DataResult>"));
$data = substr($data, 0, strpos($data, "</DataResult>") + strlen("</DataResult>"));
$xml = simplexml_load_string($data);
if ($xml === false) {
throw new Exception("Invalid user credentials.");
}
$json = json_encode($xml);
$array = json_decode($json,TRUE);
if (empty($array['Results'])) {
throw new Exception("Holiday - No Sales Data Recorded");
}
return $array['Results']['Data'];
}
private function alignmentArray($sales)
{
if ($sales['Name'] == 'Market Code' || $sales['Name'] == 'Sales Volume' || $sales['Name'] == 'Turnover Volume' || $sales['Name'] == 'Date') {
if($sales['Name'] == 'Market Code') {
$this->responseData[$sales['Instrument']]['Market Code'] = $sales['Value'];
}
if($sales['Name'] == 'Sales Volume') {
$this->responseData[$sales['Instrument']]['Sales Volume'] = $sales['Value'];
}
if($sales['Name'] == 'Turnover Volume') {
$this->responseData[$sales['Instrument']]['Turnover Volume'] = $sales['Value'];
}
else {
$this->responseData[$sales['Instrument']]['Date'] = $sales['Value'];
}
}
}
public function parser()
{
try {
$salesArray = $this->getResponseData($this->date);
} catch (Exception $e) {
$response['status'] = 'error';
$response['message'] = $e->getMessage();
$response['results'] = '';
return json_encode($response);
}
foreach ($salesArray as $sales) {
$this->alignmentArray($sales);
}
$response['status'] = 'ok';
$response['message'] = 'success';
$response['results'] = [];
foreach ($this->responseData as $row) {
array_push($response['results'], $row);
}
return json_encode($response);
}
}
?>
i'd expect that null values should still be output but whats actually happening is that no data is being returned to the HTML table.

Fatal error: cannot use stdClass as array

I've inherited some code from an ex-colleague and as it has recently been put into production it is causing us some issues. I'm not a php developer so apologies if this appears vague but it has fallen to me (don't ask!).
We are calling a function getLoan() to pre-populate an application form from an existing application. This should return an array, but I am receiving the stdClass error.
$result = getLoan(); //this is the line that is erroring
if (isset($result->GetResult->Debtor->Addresses->Address[0])) $current_address = clone $result->GetResult->Debtor->Addresses->Address[0];
else $current_address = clone $result->GetResult->Debtor->Addresses->Address;
if ($result === false)
{
echo("No LID given");
die;
}
$attr = 'selected';
and the function:
function getLoan() {
//globals
/*
global $client;
global $test;
global $result;
*/
global $thisurl;
if (isset($_GET['LID']))
$pLoanID = $_GET['LID'];
else
return false;
$test = array(
"pLoanID" => $pLoanID,
);
//print_r($Address); //print address object as a test
//send to gateway starts**********
$url = "https://www.blahblah.asmx?WSDL";
$client = new SoapClient($url, array("trace" => 1, "exception" => 0));
try {
$result = $client->Get($test);
}
catch(Exception $e) {
//header("Location: http://" . $_SERVER['REMOTE_ADDR'] . "/application-form-new");
print_r($e);
exit;
}
$thisurl = "continue-app?LID=" . $pLoanID;
if (isset($result)) return $result;
else return false;
}
How can I assign the returned value from the function to $result as an array?
Many thanks
array = json_decode(json_encode(object),true);

Php JSON Response Array

I have this php code. As you can see i query a mysql database through a function showallevents. I return a the $result to the $event variable. With the while loop i assign the values that i get from event to a response array and every time the loop happens the rows are stored in the data array. Surely i am failing somewhere because despite i am getting a correct number of responses all the values that i get at json are "null". Also it tells me something about JSONarray cannot be converted to jsonobject
if (isset($_POST['tag']) && $_POST['tag'] != '')
{
// get tag
$tag = $_POST['tag'];
// include db handler
require_once 'include/DB_Functions.php';
$db = new DB_Functions();
// response Array
$response = array("tag" => $tag, "success" => 0, "error" => 0);
// check for tag type
if ($tag == 'showallevents')
{
// Request type is show all events
// show all events
$event = $db->showallevents();
if ($event != false)
{
$data = array();
while($row = mysql_fetch_assoc($event))
{
$response["success"] = 1;
$response["uid"] = $event["uid"];
$response["event"]["date"] = $event["date"];
$response["event"]["hours"] = $event["hours"];
$response["event"]["store_name"] = $event["store_name"];
$response["event"]["event_information"] = $event["event_information"];
$response["event"]["event_type"] = $event["event_type"];
$response["event"]["Phone"] = $event["Phone"];
$response["event"]["address"] = $event["address"];
$response["event"]["created_at"] = $event["created_at"];
$response["event"]["updated_at"] = $event["updated_at"];
$data[]=$response;
}
echo json_encode($data);
}
else
{
// event not found
// echo json with error = 1
$response["error"] = 1;
$response["error_msg"] = "Events not found";
echo json_encode($response);
}
}
else
{
echo "Access Denied";
}
}
?>
the DB_Functions.php
<?php
class DB_Functions
{
private $db;
//put your code here
// constructor
function __construct()
{
require_once 'DB_Connect.php';
// connecting to database
$this->db = new DB_Connect();
$this->db->connect();
}
// destructor
function __destruct()
{
}
/**
* Select all events that are after yesterday.
*/
public function showallevents()
{
$result = mysql_query("SELECT * FROM events WHERE date >= CURDATE()");
return($result);
}
}
?>
ok the code that helped me put all data into an array was this
$data = array();
while($row = mysql_fetch_assoc($event))
{
$response["success"] = 1;
$response["event"]= $row;
$data[]=$response;
}
echo json_encode($data);
You've merged two independent pieces of code and wound up with a mess whose result is unclear.
You can create an associative array in two ways:
$array = (key=>value, key2=>value2);
You can also use:
$array[key]=value;
$array[key2]=value2;
Note that both 'key' and 'value' are simply variables; you can use strings there, or pass in a variable from someplace else.
When doing similar things, I use the following approach:
$response["success"] = 1;
$response["uid"] = $event["uid"];
$response["event"]["date"] = $event["date"];
$response["event"]["hours"] = $event["hours"];
$response["event"]["store_name"] = $event["store_name"];
$response["event"]["event_information"] = $event["event_information"];
$response["event"]["event_type"] = $event["event_type"];
$response["event"]["Phone"] = $event["Phone"];
$response["event"]["address"] = $event["address"];
$response["event"]["created_at"] = $event["created_at"];
$response["event"]["updated_at"] = $event["updated_at"];
$data[]=$response;
What is your $response variable?
In PHP to create associative arrays, you use => and not =
for example:
$array = ('key1' => 'value1', 'key2' => 'value2');
if you just want to return all the arrays, can you use mysql_fetch_assoc in stead of mysql_fetch_row?
if ($tag == 'showallevents')
{
// Request type is show all events
// show all events
$event = $db->showallevents();
if ($event != false)
{
$data = array();
while($row = mysql_fetch_assoc($event))
{
$data[] = $row;
echo json_encode($data);
}
else
{
// event not found
// echo json with error = 1
$response["error"] = 1;
$response["error_msg"] = "Events not found";
echo json_encode($response);
}
}
else
{
echo "Access Denied";
}
}
?>

Base64 String to Image

I hava a rest-webservice and i want to upload the image as a base64 string and decode it on my webserver using php.
My Code:
if (isset($para['picture']) or isset($para['filetype']) )
{
if (isset($para['picture']) and isset($para['filetype']))
{
if (!($para['filetype'] == 'jpg' || $para['filetype'] == 'png'))
{
$arr['Code'] = 617;
$arr['Message'] = $msg->getMessage(617);
$response->body = json_encode($arr);
return $response;
}
echo $para['picture'];
$bin = base64_decode(str_replace(' ', '+', $para['picture']));
if (strlen($bin) >(524288*2))
{
$arr['Code'] = 624;
$arr['Message'] = $msg->getMessage(624);
$response->body = json_encode($arr);
return $response;
}
$uid = $dbmodel->getUid($sid);
if($uid<1)
{
$arr['Code'] = 699;
$arr['Message'] = $msg->getMessage(699);
$response->body = json_encode($arr);
return $response;
}
$file = fopen($_SERVER['DOCUMENT_ROOT']."/img/".$uid.".".$para['filetype'], 'w');
fwrite($file, $bin);
fclose($file);
$dbmodel->insertPicture($uid,URL_ROOT."/img/".$uid.".".$para['filetype']);
}
else
{
$arr['Code'] = 616;
$arr['Message'] = $msg->getMessage(616);
$response->body = json_encode($arr);
return $response;
}
DBModel:
function insertPicture($uid,$link)
{
$result = mysql_query("select link from USER_PICTURE where USER_ID=$uid");
if (mysql_num_rows($result)==1)
{
$row = mysql_fetch_array($result);
$row['link'];
$split = explode("/img/", $row['link']);
unlink($_SERVER['DOCUMENT_ROOT']."/img/".$split[1]);
}
$result = mysql_query("INSERT INTO USER_PICTURE (user_id,link) VALUES ($uid, '$link')ON DUPLICATE KEY UPDATE link='$link'");
if ($result)
{
return true;
}
return false;
}
I call my webservice with:
sid=3rcsg42ekbiats33uf2jto6u16&picture=/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAEEAQQDASIAAhEBAxEB/8QAHQABAAEFAQEBAAAAAAAAAAAAAAECAwQGBwUICf/EAD0QAAEDAwIEBAQEBAQGAwAAAAEAAgMEBREGIQcSMUETUWFxCBQikTKBobEVI0LRJWLB4RYXMzRSckSi8f/EABwBAQABBQEBAAAAAAAAAAAAAAABAgQFBgcDCP/EADQRAAIBAwMCBAQDCAMAAAAAAAABAgMEEQUhMQYSE0FRYSJxgZEUQqEVFjIzscHR8CPh8f/aAAwDAQACEQMRAD8A/VNERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQEIXYVLngYVD3HrhAXOcYTnCx/Ez02TmyfX26ISZHOCcAqenqsfmPmFWHFpyhBeRUNkyVWgIQqUQBFCZQEoo5h5qOYHugKlCpc/HXZOcY6oCpSqQ7IU8w80BKKljw5OYeYQFSKAQVKAhSoUoAijupQBFClAEREAREQBERAWTgFCMgqBv/dSMgY6oCwWEHZT+P8PsrrhnHRM+uyE5LIyDuce6vN3aFBaCD0ypY3lQE4OfI+qrY76VRzEeqAZ2P7IQXA4JzBU8mdhjHkqHtIOUBeO6tuY4dFbEjgdwq2zjfPZRknBbdK4bEZVLZVkZD29FQYmk4AGVII5wcdMqPEB74VPh9sqHR46HPoo3GxcEoHcKoTDCxgPyUjpuoyTgyg/bqFSRkDdWA4hVB7huN/dTkjBfa7GU51Z8XByR1VYcCOo/NStyC5zqPEG+yoO/TooI6nO6Ar8XHQKRJ3OFYccDPUq0X8vVRknBnNeHdFOVgiqI9VW2oaT5H0UkGYisMl9furjZATv1QFaIiAIiICxnOR0QANaAAABthTzDqFBOfVASD6/ZU7g/2TJHQZUta4b5/RAAemybkdsqQN+mVJHfG6AoPfcZVXfuqSMfmpceuP1QFQI81PMO6o29Cp5h5ICRh3qrbo275wFWHgEoXg46eiAtYczrhAXEdFdL8DooLtxsFBOS015B6IHlvU9VU4BwPb3CtuB2PdUt4JW5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iID/9k=&filetype=jpg
I use the notepadd++ with mimetype plugin to convert a image to base64
UPDATE:
Picture Paramter in PHP:
/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAEEAQQDASIAAhEBAxEB/8QAHQABAAEFAQEBAAAAAAAAAAAAAAECAwQGBwUICf/EAD0QAAEDAwIEBAQEBAQGAwAAAAEAAgMEBREGIQcSMUETUWFxCBQikTKBobEVI0LRJWLB4RYXMzRSckSi8f/EABwBAQABBQEBAAAAAAAAAAAAAAABAgQFBgcDCP/EADQRAAIBAwMCBAQDCAMAAAAAAAABAgMEEQUhMQYSE0FRYSJxgZEUQqEVFjIzscHR8CPh8f/aAAwDAQACEQMRAD8A/VNERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQBERAEREAREQEIXYVLngYVD3HrhAXOcYTnCx/Ez02TmyfX26ISZHOCcAqenqsfmPmFWHFpyhBeRUNkyVWgIQqUQBFCZQEoo5h5qOYHugKlCpc/HXZOcY6oCpSqQ7IU8w80BKKljw5OYeYQFSKAQVKAhSoUoAijupQBFClAEREAREQBERAWTgFCMgqBv/dSMgY6oCwWEHZT+P8PsrrhnHRM+uyE5LIyDuce6vN3aFBaCD0ypY3lQE4OfI+qrY76VRzEeqAZ2P7IQXA4JzBU8mdhjHkqHtIOUBeO6tuY4dFbEjgdwq2zjfPZRknBbdK4bEZVLZVkZD29FQYmk4AGVII5wcdMqPEB74VPh9sqHR46HPoo3GxcEoHcKoTDCxgP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AREQBERAUEOLgdsfqqlKIAoUogCp3yqkQBR0UogCIiAIiIAoKlEBTg49VQYznzV1EBY8J2MYUeE7AGP1WQiE5MYQvz0291SaZx7fqstEGTDNM/s39VBppCNm/qs1EGTCbTPA/D+qvxxub2V5EIIHRFKIAiIgCIiAIiIAiIgCIiAIiIAiIgCIiAIiIAiIgCIiAIiIAiIgCIiAIiIAiIgCIiAIiIAiIgCIiAIiIAiIgCIiAIiIAiIgCIiAIiIAiIgCIiAIiIAiIgCIiAIiIAiIgCIiAIiIAiIgCIiAIiIAiIgCIiAIiIAiIgCIiAIiIAiIgCIiAIiIAiIgCIiAIiID/9k=
Problem:
The DB Link will be set right, but the image doesn't appear in the webroot.
Please help
There is a "%3D" at the end of your base64 string. But there is no "%" in the base64 alphabet.
If this makes it into your image files, they might be invalid.
Regards
Stefan

REST Webservice HTTP_PUT parameter

I make with tonic (php library for rest ) a rest webservice.
I use according to CRUD and REST put for editing a element.
So i call my method with a picture and filetype and parse the paramters and save the base64 encoded file on my server.
Code:
function put($request) {
$response = new Response($request);
$msg = new ErrorMessage();
$dbmodel = new DBModel();
$arr = array('Data' => null,'Message' =>null,'Code' => null);
try{
$split = explode ('&',$request->data);
$para = array();
foreach($split as $i) {
$names = explode('=',$i);
if(!isset($names[0]) or !isset($names[1]))
{
throw new Exception();
}
$para[$names[0]] = $names[1];
}
}
catch(Exception $e)
{
$arr['Code'] = 400;
$arr['Message'] = $msg->getMessage(400);
$response->body = json_encode($arr);
return $response;
}
if (isset($para['picture']) or isset($para['filetype']) )
{
if (isset($para['picture']) and isset($para['filetype']))
{
if (!($para['filetype'] == 'jpg' || $para['filetype'] == 'png'))
{
$arr['Code'] = 688;
$arr['Message'] = $msg->getMessage(617);
$response->body = json_encode($arr);
return $response;
}
$bin = base64_decode($para['picture']);
if (strlen($bin) >524288)
{
$arr['Code'] = 617;
$arr['Message'] = $msg->getMessage(617);
$response->body = json_encode($arr);
return $response;
}
$uid = $dbmodel->getUid($sid);
if($uid<1)
{
$arr['Code'] = 699;
$arr['Message'] = $msg->getMessage(699);
$response->body = json_encode($arr);
return $response;
}
$file = fopen($_SERVER['DOCUMENT_ROOT']."/img/".$uid.".".$para['filetype'], 'wb');
fwrite($file, $bin);
fclose($file);
}
else
{
$arr['Code'] = 616;
$arr['Message'] = $msg->getMessage(616);
$response->body = json_encode($arr);
return $response;
}
}
$arr['Code'] = 200;
$arr['Message'] = $msg->getMessage(200);
$response->body = json_encode($arr);
return $response;
}
Problem: The saved picture isn't like the original one it can't be displayed as image
I use http://www.redio.info/werkzeuge/file2base64.html to convert my picture into base64. I think that the problem could be in the parsing at the beginning of my code.
Original: 13.872 Bytes
New Image: 14.313 Bytes
Your picture parameter gets probably urlencoded, that would explain the bigger filesize. (e.g. '/' to %2F)
Try to put a urldecode around the parameter before you decode it.
$bin = base64_decode(urldecode($para['picture']));

Categories