I have the following JSON string, which was an Objective C array then encoded to JSON:
$jsonString=[\"[email protected]\",\"[email protected]\",\"[email protected]\"]
I want to convert this to a regular PHP array. I've tried many things but none of them seem to work:
$arrayOfEmails=json_decode($jsonString); //doesn't work
$arrayOfEmails=(array)json_decode($jsonString); //doesn't work
Any ideas?
Edit:
I'm still not getting it to work.
$decodeEmails=$_POST["arrayOfEmails"];
sendResponse(200, $decodeEmails);
//the above returns exactly whats after this colon:[\"[email protected]\",\"[email protected]\",\"[email protected]\]
I need to do this: $arrayOfEmails=json_decode($decodeEmails);
But I think I need quotes around $decodedEmails for this to work. How can I add quotes around $decodeEmails string?
Try this:
json_decode($json_string, true);
You should quote your string, it works fine, see here.
$jsonString = '["[email protected]","[email protected]","[email protected]"]';
$arrayOfEmails=json_decode($jsonString);
Or
$jsonString = "[\"[email protected]\",\"[email protected]\",\"[email protected]\"]";
$arrayOfEmails=json_decode($jsonString);
$data = unserialize($data)
now u can get the $data as array
For example $data have the value like this
$data = "a:2:{s:18:"_1337666504149_149";a:2:{s:8:"fbregexp";s:1:"1";s:5:"value";s:4:"2222";}s:18:"_1337666505594_594";a:2:{s:8:"fbregexp";s:1:"3";s:5:"value";s:5:"45555";}}";
$data = unserialize($data)
now i get value like this
Array ( [fbregexp] => 1 [value] => 2222 ) [_1337666505594_594] => Array ( [fbregexp] => 3 [value] => 45555 ) )
$str=<<<H
{"a":"AAA","b":"333"}
H;
$object = json_decode($str);
$array = json_decode($str , 1 );
// $arr = get_object_vars( json_decode($str) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With