Monday 15 February 2010

java - JSON response is not working in PHP version 5.3.24 -



java - JSON response is not working in PHP version 5.3.24 -

i developing java application have pass values server , receive response php file (version 5.3.24).the code running fine in localhost , other live servers php version greater 5.3.24.

this java code.

public static void send() { seek { // create json string, seek hamburger string json = "{\"name\":\"frank\",\"food\":\"pizza\",\"quantity\":3}"; // send http request url url = new url("http://www.matjazcerkvenik.si/php/json/pizzaservice.php?order="+json); urlconnection conn = url.openconnection(); // response bufferedreader rd = new bufferedreader(new inputstreamreader(conn.getinputstream())); string line; while ((line = rd.readline()) != null) { system.out.println(line); } rd.close(); } grab (exception e) { e.printstacktrace(); } } public static void main(string[] args) { send(); }

this php code.

<?php $order = $_get["order"]; $obj = json_decode($order); $name = $obj -> {"name"}; $food = $obj -> {"food"}; $quty = $obj -> {"quantity"}; if ($food == "pizza") { $price = 4000; } else if ($food == "hamburger") { $price = 5000; } else { $price = 0; } $price = $price * $quty; if ($price == 0) { $status = "not-accepted"; } else { $status = "accepted"; } $array = array("name" => $name, "food" => $food, "quantity" => $quty, "price" => $price, "status" => $status); echo json_encode($array); ?>

change php script bit:

<?php $order = get_magic_quotes_gpc() ? stripslashes($_get["order"]) : $_get["order"]; $obj = json_decode($order); $name = $obj -> {"name"}; $food = $obj -> {"food"}; $quty = $obj -> {"quantity"}; if ($food == "pizza") { $price = 4000; } else if ($food == "hamburger") { $price = 5000; } else { $price = 0; } $price = $price * $quty; if ($price == 0) { $status = "not-accepted"; } else { $status = "accepted"; } $array = array("name" => $name, "food" => $food, "quantity" => $quty, "price" => $price, "status" => $status); echo json_encode($array); ?>

java php json

No comments:

Post a Comment