Try trimming:
foreach($res->result() as $row ){
$product=$row->product_name;
$products=json_decode(trim($product), 1);
print_r($products);
}
Tried:
var_dump(json_decode('[{"product_id":"1","product_name":"Apple iMac","quantity":"32","unit":"23","unit_rate":"32"},{"product_id":"5","product_name":"Nokia E5","quantity":"543","unit":"543","unit_rate":"543"},{"product_id":"8","product_name":"Zinc Sulphate 500 ml","quantity":"5443","unit":"434","unit_rate":"5333"}]'));
UPDATE:
Not sure but, it can be this bug. I can see the white space between Apple iMac
. One option left is to try updating PHP, this might be too much.
Try test cases from the bug link:
Test script:
function json_cmp($x, $y)
{
print var_dump(json_decode($x) === $y);
}
// works
json_cmp("true", true);
// fails - is actually true
json_cmp("tRue", NULL);
// fails - is actually NULL
json_cmp("true ", true);
// works
json_cmp("[true ] ", array(true));
// works, even though the non-array version fails
json_cmp("[tRue]", NULL);
?>
Expected result:
true * 5
Actual result:
bool(true)
bool(false)
bool(false)
bool(true)
bool(true)
No comments:
Post a Comment