2

here I use this code in my local host

$fromdata= $_POST["data"];
$fromValue=json_decode($fromdata);
$patientid=  $fromValue->patientid;
$patientname= $fromValue->name;

its working fine... if i use

print_r($fromdata); 

it print the following format

{"patientid":"55","name":"Sow"}

. the same code is used in wordpress the print_r($fromdata); return {\"patientid\":\"16\",\"name\":\"Ravindran\"} this. and unable to get value

how to get value from this object thanks

1
  • What do you you get when you execute print_r($_POST["data"]);? Commented Jun 1, 2017 at 16:03

1 Answer 1

8

Due to a longstanding quirk, you'll need to first use stripslashes to remove the extra slashes that WordPress adds to the request's JSON string.

The pre-stripped data looks something like this:

$json_string = '{\"patientid\":\"16\",\"name\":\"Ravindran\"}';

So to convert it, you'll need to do something like this:

$object = json_decode(stripslashes($json_string));

Or if you instead want an associative array:

$array = json_decode(stripslashes($json_string), true);
Sign up to request clarification or add additional context in comments.

1 Comment

yep. That fixed it.

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.