I have the following code:
$option = $this->request->post['option'];
var_dump($option);
echo "<br>";
var_dump(json_decode($option));
The dumps show:
string(118) "{'product_option_id':276, 'product_option_value_id':132, 'name':'Цветове', 'value':'Бял', 'type':'select'}"
And the second one (json_decode):
NULL
Why the string can't be parsed ?
EDIT: now my json looks like this:
string(205) "{"product_option_id": 280, "product_option_value_id": 133, "name": "Цветове", "value": "Бежов", "type": "select"}"
And i added this to my code:
switch (json_last_error()) {
case JSON_ERROR_NONE:
echo ' - No errors';
break;
case JSON_ERROR_DEPTH:
echo ' - Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
echo ' - Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
echo ' - Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
echo ' - Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
echo ' - Unknown error';
break;
}
and i returns Syntax error, malformed JSON