Javascript 将JSON转换为经典ASP的PHP
我正在开发android应用程序的登录部分。有一个PHP页面,它使用JSON从应用程序获取输入,并将其查询到SQL数据库,然后返回登录是否成功 现在,我的老板不想要PHP页面,它必须是ASP 如何将PHP页面转换为使用vbscript/javascript的ASP页面 我发现 不确定如何转换json_编码 PHP页面代码:Javascript 将JSON转换为经典ASP的PHP,javascript,php,json,vbscript,asp-classic,Javascript,Php,Json,Vbscript,Asp Classic,我正在开发android应用程序的登录部分。有一个PHP页面,它使用JSON从应用程序获取输入,并将其查询到SQL数据库,然后返回登录是否成功 现在,我的老板不想要PHP页面,它必须是ASP 如何将PHP页面转换为使用vbscript/javascript的ASP页面 我发现 不确定如何转换json_编码 PHP页面代码: <?php mysql_connect("localhost","user","pass"); $db= mysql_select_db("database");
<?php mysql_connect("localhost","user","pass");
$db= mysql_select_db("database");
$androidID=$_POST["androidID"];
$username=$_POST["username"];
if (!empty($_POST)) {
if (empty($_POST['username']) || empty($_POST['androidID'])) {
// Create some data that will be the JSON response
$response["success"] = 0;
$response["message"] = "One or both of the fields are empty .";
//die is used to kill the page, will not let the code below to be executed. It will also
//display the parameter, that is the json data which our android application will parse to be
//shown to the users
die(json_encode($response));
}
$query = " SELECT id, username, aid FROM login WHERE username = '$username'and aid='$androidID'";
$sql1=mysql_query($query);
$row = mysql_fetch_array($sql1);
if (!empty($row)) { $response["success"] = 1;
$response["message"] = "You have been sucessfully login";
die(json_encode($response));
}
else{
$response["success"] = 0; $response["message"] = "invalid username or password ";
die(json_encode($response));
}
}
else{ $response["success"] = 0;
$response["message"] = " One or both of the fields are empty ";
die(json_encode($response));
}
mysql_close();
?>
我不是PHP专家,但我认为die()
会将传递给它的字符串返回给客户端并停止脚本
我认为等效的ASP应该是
response.write json_encode(responseObject)
response.end
那么问题是如何编写json\u encode
就我个人而言,给出这个确切的例子,我将通过手工编码JSON响应来简化任务:
response.write "{success:1, message:""You have been successfully login""}"
response.end
这就避免了需要弄清楚如何实现一个通用的JSON编码方法来完成这个非常简单的事情。您可以编写一个方法,该方法接受一个成功代码和一个消息字符串,如果需要,还可以返回一个JSON字符串,从而使其更具通用性