Json decode in wordpress

2019-09-19 13:51发布

问题:

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:

You can try this.

<?php

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

$data = stripslashes($data);

$return = json_decode($data);



print_r($return);