Pre Exam Test Practice (SSC | Banking | IAS | GATE | State Level | CLAT | Railways | Insurance | Teaching Exams | NDA | Defence | IES |State Exam )

Organizational Research By

Surprising Reserch Topic

detecting json decode failure in php using -'php,json'

detecting json decode failure in php  using -'php,json'

When using PHP's json_decode(), I don't see a way to distinguish between a NULL return value indicating a failure in decoding and a correctly decoded NULL value:

var_dump(json_decode('nonsense')); // returns NULL
var_dump(json_decode(json_encode(NULL))); // also returns NULL

And case one doesn't throw an exception. So I'm not sure how to test for a decode failure.


asked Sep 7, 2015 by rajesh
0 votes

Related Hot Questions

Government Jobs Opening