0

i am using json decoding function in php to decode this

{"department_id":"3123a79d-9e33-543f-c9be-4cc7ff79982c",
"ug_id":"217a783c-7970-8d92-6c99-5225a3ec533a",
"pg_id":"90da4eb5-6b75-44b0-2ce0-5226c8f60f8e",
"staff_id":"1e6364a3-0b3d-6384-a6c2-5225bd41c7fd",
"from_date":"date_start",
"to_date":"date_end"}

I have use json_decode($str) and json_decode($str,true) both, but i am getting null output. Please help me if possible. Here is my complete code

$query='SELECT params FROM userreports WHERE id=\''.$_REQUEST['record'].'\'';
            $query_exe=$db->query($query);
            $res=$db->fetchByAssoc($query_exe);

                $json=$res['params'];
                $arr=json_decode($json,true);
                echo '<pre>';
                print_r($arr) ;exit;
Deepesh
  • 180
  • 16

1 Answers1

0

Try following code it is working fine:

<?php
$str = '{"department_id":"3123a79d-9e33-543f-c9be-4cc7ff79982c",
"ug_id":"217a783c-7970-8d92-6c99-5225a3ec533a",
"pg_id":"90da4eb5-6b75-44b0-2ce0-5226c8f60f8e",
"staff_id":"1e6364a3-0b3d-6384-a6c2-5225bd41c7fd",
"from_date":"date_start",
"to_date":"date_end"}';

$arrStr = json_decode($str);

print_r($arrStr);

?>
Vipin Singh
  • 543
  • 2
  • 8
  • 24