sending json data using curl php -


i want send data using php,curl. have de following code string containing data :

 <?php  $string='  {     "unidad": [  { "baterias": { "bat1": "10", "bat2": "18", "bat3": "13", "bat4": "18" }              },  { "lineas": { "line1": "110", "line2": "128", "line3":         "130", "line4": "125" } },  { "ampers": { "amp1": "10", "amp2": "7", "amp3": "13" }  }  ]  }';  $jsondataencoded=json_encode($string,true); $curl_connection = curl_init('http://172.27.17.210:81/recv_json.php'); curl_setopt($curl_connection, curlopt_connecttimeout, 30); curl_setopt($curl_connection, curlopt_useragent, "mozilla/4.0 (compatible;       msie 6.0; windows nt 5.1)"); curl_setopt($curl_connection, curlopt_returntransfer, true); curl_setopt($curl_connection, curlopt_ssl_verifypeer, false); curl_setopt($curl_connection, curlopt_followlocation, 1); 

curl_setopt($curl_connection, curlopt_httpheader, array('content-type: application/json')); curl_setopt($curl_connection, curlopt_postfields, $jsondataencoded); $result = curl_exec($curl_connection); echo $result; curl_close($curl_connection); ?>

and have de following php file process data :

enter code here   <html> <body> <?php $json_input_data=json_decode(file_get_contents('php://input'),true); echo gettype($json_input_data)."\n"; echo $json_input_data; ?> </body> </html> 

the result string, want know how convert string array can access fields contained in it.

thanks


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -