1

I am sending the query with an url as POST parameters and the parameters are JSON encoded. I am new to both JSON and PHP. I have no idea how to capture the JSON encoded parameters in a PHP file and how to decode them so that I can get individual key and value pairs. Any kind of help is appreciated. In this context I would like to add one thing i.e. I am passing the parameters by Chrome POST man REST client. Thank you.

1
  • I did this job yesterday, an gave an example in my answer, hope it would be helpful. Good luck. Commented Jul 23, 2013 at 3:55

2 Answers 2

2

use json_decode()

if you like to have the json_decode return an object use $obj = json_decode($json_str); and if you like to have an associative array returned $array = json_decode($json_str, true);

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

Comments

0

You can use file_get_contents to get the response as a one big string and then json_decode to decode the response.

http://php.net/manual/en/function.file-get-contents.php

http://php.net/manual/en/function.json-decode.php

4 Comments

I think my question is not clear. I apologize for that. Actually I am using Chrome POSTMan REST client to pass those parameters and want to handle them in a PHP file. So here could you please give me some guidance?
I've never used it before. what does POSTMan Rest return if anything to you?
Actually it is kind of Add on of Chrome browser. There you can paste the URL above and paste the parameters that you want to pass with URL, you write them in a box below it and click the SEND button below. Thereby you can pass any number of parameters you want.
You need to get the response from POSTMan. Just as a string will do. So you can use file_get_contents('filename'). Or if POSTMan returns the json code, which will look something like'{"a":1,"b":2,"c":3,"d":4,"e":5}, then take that and store it as a variable, $response = '{"a":1,"b":2,"c":3,"d":4,"e":5}'. Then json_decode($reponse) will break it into name value pairs. It;s all in the links I put in my answer above. Although how it relates with POSTMan I don't know as I said i've never used it. But it should be fairly easy to do.

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.