I have developed a web service using php(zend) which receives array of parameters from ios app, but when the ios app sends the parameters, the web service receives them as string, and I can't convert it into array so I can't handle the request
received string format like this
(
{
"parm1" = "val1";
"parm2" = val2;
"parm3" = val4;
}
)
How can I convert this json into array?
It looks like JSON format. Pass this string to method json_decode and it will convert it to an array for you (or any other object it was encoded from).
Just use json_decode
to decode this json into array. Use the code below
$json = ' (
{
"parm1" = "val1";
"parm2" = val2;
"parm3" = val4;
}
)';
$array = json_decode($json,true); // this is the array
Hope this helps you
Consider you are getting
$json = ' (
{
"parm1" = "val1";
"parm2" = val2;
"parm3" = val4;
}
)';
$array = json_decode($json,true); // this is the array
And you will get parameters :
$parm1 = $array->parm1;
$parm2 = $array->parm2;
$parm3 = $array->parm3;
json_decode
takes a JSON encoded string and converts it into a array.