JSON响应在PHP 5.3.24版本中不起作用


JSON response is not working in PHP version 5.3.24

我正在开发一个Java应用程序,在该应用程序中,我必须将值传递到服务器,并从PHP文件(版本5.3.24)接收响应。该代码在localhost和其他PHP版本大于5.3.24的实时服务器上运行良好。

这是我的Java代码。

public static void send() {
try {
// make json string, try also hamburger
String json = "{'"name'":'"Frank'",'"food'":'"pizza'",'"quantity'":3}";
// send as http get request
URL url = new URL("http://www.matjazcerkvenik.si/php/json/pizzaservice.php?order="+json);
URLConnection conn = url.openConnection();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
rd.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
send();
}

这是我的PHP代码。

<?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);
?>

稍微更改一下php脚本:

<?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);
?>