cancel
Showing results for 
Search instead for 
Did you mean: 

Help with decoding json data

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Help with decoding json data

If I run the following everything works as expected

$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
var_dump(json_decode($Response));
var_dump(json_decode($json, true));

But when I run the following I get an error

$response = curl_exec($ch);
$json_response = json_decode($response);
var_dump(json_decode($json_response));

Returned data looks like this when I echo to screen,

{ "STANDARDUNIT":"Each", "UNITDESCRIPTION":"Each", "ISTIMEUNIT":0, "TIMEPERHOUR":0, "UPPERSTANDARDUNIT":"EACH", "SYSDATECREATED":"14/11/2006 1:54:36 PM", "SYSDATEMODIFIED":"14/11/2006 1:54:36 PM", "SYSUNIQUEID":10075, "SYSUSERCREATED":"", "SYSUSERMODIFIED":"" }

 

Error when I try to run the page with 'var_dump(json_decode($json_response));' active:

There has been an error processing your request

Exception printing is disabled by default for security reasons.

Error log record number: 1133047947559

 

Everything works without a hitch until I try to print or access the return data in Json format. I have tried returning the data as application/json and text/html but nothing seems to be working.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Help with decoding json data

Hey @kevin_marshall2 

 

Please run the following code to get rid of the error:

 

$response = curl_exec($ch);
$json_response = json_decode($response);
var_dump($json_response);

 

Do let me know if it was helpful, or you need any further assistance.

---
If you've found my answer useful, please give"Kudos" and "Accept as Solution"

View solution in original post

2 REPLIES 2

Re: Help with decoding json data

Hey @kevin_marshall2 

 

Please run the following code to get rid of the error:

 

$response = curl_exec($ch);
$json_response = json_decode($response);
var_dump($json_response);

 

Do let me know if it was helpful, or you need any further assistance.

---
If you've found my answer useful, please give"Kudos" and "Accept as Solution"

Re: Help with decoding json data

Thanks for that, it worked but I cannot seem to access any of them by reference name. I have tried both of the following. the first gives a fatal error, the second return 404 page not found.

 

echo $json_response['STANDARDUNIT'];
echo $json_response.['STANDARDUNIT'];

var_dump displays

object(stdClass)#973 (10) { ["STANDARDUNIT"]=> string(4) "Each" ["UNITDESCRIPTION"]=> string(4) "Each" ["ISTIMEUNIT"]=> int(0) ["TIMEPERHOUR"]=> int(0) ["UPPERSTANDARDUNIT"]=> string(4) "EACH" ["SYSDATECREATED"]=> string(21) "14/11/2006 1:54:36 PM" ["SYSDATEMODIFIED"]=> string(21) "14/11/2006 1:54:36 PM" ["SYSUNIQUEID"]=> int(10075) ["SYSUSERCREATED"]=> string(0) "" ["SYSUSERMODIFIED"]=> string(0) "" }

 

FIXED