tuyenle tuyenle - 8 days ago 8
PHP Question

json_decode NULL on $_GET

I have a

$("#stateAttr").serializeArray
pass from input submit form to php page in this format

[{"name": "data[stateAttr]", "value": "california, 38.8 million, golden state, 163,696 mi square, 2,448 trillion, sacramento"}]


on the php page I did
$b = $_GET["data"]["stateAttr"]
and tried to get the "value" of the array by using
var_dump(json_decode($b))
and I got NULL instead

How do I unserialize the array to get the "value"?

Update:
I did this on the client side and got the format like above. I just want to get the value of key "value"

var stateAttr = $("#stateAttr").serializeArray;
stateInput.setAttribute("value", stateAttr);
stateInput.setAttribute("name", "data[stateAttr]");

Answer

Try this to get the value:

$data= json_decode('[{"name": "data[stateAttr]", "value": "california, 38.8 million, golden state, 163,696 mi square, 2,448 trillion, sacramento"}]');
print_r($data[0]->value);
Comments