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.
2 Answers
You can use file_get_contents to get the response as a one big string and then json_decode to decode the response.
4 Comments
Joy
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?
Jonnny
I've never used it before. what does POSTMan Rest return if anything to you?
Joy
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.
Jonnny
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.