0

I'm trying to parse JSON sent by POST to my webservice. I'm using Advanced Rest Client tool for Google Chrome to test restapi.

How can I read this request and response to it?

I'm sending key called "format" and "json" as value for this key. I'm adding JSON like

"{"id":"235325"}"

Part of my PHP API code:

if( strcasecmp($format,'json') == 0 )
{
 //how to read that id = 235325?
}
vhu
12.9k11 gold badges42 silver badges50 bronze badges
asked Aug 20, 2015 at 18:10
4
  • can you past the content of var_dump($_POST)? Commented Aug 20, 2015 at 18:17
  • but how? I'using Google Chrome plugin called Advanced Rest Client. And i'am waiting for response. i dont kwno how to attach this json: "{"id":"235325"}" to link: 78.28.23.180/index2.php?format=json on webbrowser Commented Aug 20, 2015 at 18:23
  • the plugin may not support post data, use curl from your application and post data a to file expecting post. return the result. Commented Aug 20, 2015 at 18:43
  • @mdamia the problem is not getting the data to the server, but how to handle it once it is Inside the server Commented Aug 20, 2015 at 19:38

2 Answers 2

4

Try the json_decode() function. It is the standard function to parse json in php.

answered Aug 20, 2015 at 19:36

1 Comment

Would it help the OP, and other viewers of your answer, to explain why this function applies to this problem? And a visit to the manual will be worthwhile?
0

If want to work with array:

$json = '{"id":"235325"}';
$array = json_decode($json, true);
foreach($array as $element){
if($element == 0){
}
}

With object:

$json = '{"id":"235325"}';
$object = json_decode($json);
if($object->id == 0){
}
answered Aug 20, 2015 at 20:59

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.