{ "student": [{ "Name": "John", "Number": "1234567890" }, { "Name": "Jonny", "Number": "0987654321" }, { "Name": "Tom", "Number": "0212365895" }] }
<?php //http://localhost:8080/sample1/webservice2.php?json={%22UserName%22:1,%22FullName%22:2} //$json=$_GET ['json']; $json = file_get_contents('php://input'); $obj = json_decode($json); echo $json; //Save $con=mysql_connect("localhost","USERNAME","PASSWORD"); mysql_select_db("DATASASE",$con); /* grab the posts from the db */ //$query = "SELECT post_title, guid FROM wp_posts WHERE post_author = $user_id AND post_status = 'publish' ORDER BY ID DESC LIMIT $number_of_posts"; //for($i=0;i<count($obj);$i++){ mysql_query("INSERT INTO Contact (Name, Number) VALUES ('".$obj->{'student'}{'Name'}."', '".$item->{'Number'}."')"); //} mysql_close($con); // //$posts = array($json); $posts = array(1); header('Content-type: application/json'); echo json_encode(array('posts'=>$posts)); ?>
$name = $obj->student[index]->Name; $number = $obj->student[index]->Number;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)