0

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?

2
  • already u getting array bro Commented Mar 13, 2015 at 5:18
  • Use json_decode function to convert it into array. Commented Mar 13, 2015 at 5:19

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Looks like you copied it from me.. +1
Yes, It look like that but bro when there is one answer then that may look somewhat same.
I was talking about this comment // this is the array . There is no change in that
1

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).

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.