php - Trouble accessing JSON data through URL with CakePHP -


i'm passing data knockout.js form controller in cakephp, i'm bit confused how access data.

the url being passed

orders/submit_order/%7b"orderinfo":[%7b"itemnumber":"1","quantity":"1","price":1.00,"productname":"test product"%7d]%7d 

in controller tried echo url after decoding came null every time. debugged , found out it's showing named parameter

function submit_order($order = null){     $this->layout = false;     $this->autorender = false;     $order = json_decode($order, true);     $print_r($order); //shows null     debug($this->params);      //$order_2 = json_decode($this->request->params['named'], true); //says string required, array given     $order_2 = $this->request->params['named'];     print_r($order_2);     echo $order_2['orderinfo'][0]['itemnumber']; } 

the debug statement returns following

object(cakerequest) { params => array(     'plugin' => null,     'controller' => 'orders',     'action' => 'submit_order',     'named' => array(         '{"orderinfo"' => '[{"itemnumber":"1","quantity":"1","price":1.00,"productname":"test product"}]}'     ),     'pass' => array() ) 

when print $order_2 following displays.

array ( [{"orderinfo"] => [{"itemnumber":"1","quantity":"1","price":1.00,"productname":"test product"}]} ) 

i wrong, bracket/brace placement seems strange.

when try echo itemnumber, gives me error stating it's undefined index. noticed it's not staggered line-by-line array is.

how can access data?


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -