json - PHP json_decode not working - displays NULL output -


i'm trying use json decode retrieve information it's not working, it's showing data null when use var_dump

here's json formatted data passed in url

ordersummary={"orderinfo":[{"itemnumber":"1","quantity":"3","price":"5.99","productname":"item_b"}]} 

when echo un-decoded string following

echo $_get['ordersummary']; //displays following {\"orderinfo\":[{\"itemnumber\":\"1\",\"quantity\":\"3\",\"price\":\"5.99\",\"productname\":\"item_b\"}]} 

however, when try decode result null

$order = $_get['ordersummary']; $data = json_decode($order,true); echo "<pre>"; var_dump($data); die(); //displays following <pre>null 

is not formatted?

run input string through stripslashes() first.

$input = '{\"orderinfo\":[{\"itemnumber\":\"1\",\"quantity\":\"3\",\"price\":\"5.99\",\"productname\":\"item_b\"}]}';  print_r(json_decode(stripslashes($input))); 

output

stdclass object (     [orderinfo] => array         (             [0] => stdclass object                 (                     [itemnumber] => 1                     [quantity] => 3                     [price] => 5.99                     [productname] => item_b                 )          )  ) 

demo

alternatively

turn off magic_quotes_gpc. considering has been deprecated (and removed in 5.4), this better option.


Comments

Popular posts from this blog

Pull out data related to my apps from Android Play Store and iOS App Store -

Change php variable from jquery value using ajax (same page) -

How can I fetch data from a web server in an android application? -