【发布时间】:2011-04-21 03:41:53
【问题描述】:
如何在 xampp 服务器中安装 json?
【问题讨论】:
-
你的意思是php扩展???
-
Ravi:您知道吗:您可以编辑您的问题,因此请在您的问题中包含此信息以改进它。另一个可能会帮助您获得更好投票和更多答案的提示:转到您的旧问题并接受对您最有帮助的每个问题的答案(通过单击旁边的复选标记。
如何在 xampp 服务器中安装 json?
【问题讨论】:
Json 是format;你不安装它,你实现它。
如果你想在你的 php 网站中使用 json 格式,有一个提供functions 的扩展,你可以使用encode data in a json format。
要安装或使用扩展,请参阅installation page;根据您的 php 版本,您可能已经将 json 扩展与 xampp 捆绑在一起。如果你有xampp(windows安装)的latest version,直接使用方法就可以了
【讨论】:
Xampp 与 Apache、MySQL、PHP、Perl 一起“发布”,并支持 PHP 和 Perl 中的 JSON!
Json Perl: JSON::to_json(hash);
<?php
$arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);
echo json_encode($arr);
?>
编辑: 第二个例子展示了如何 json_encode() 一个 mysql 查询结果:
<?php
$sth = mysql_query("SELECT ...");
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
?>
编辑 2:然后您可以使用this stackoverflow question 中描述的方法之一将 JSON 转换为 XML。
Edit3:如果要将xml文件保存到光盘使用
$myFile = "file.xml";
$fh = fopen($myFile, 'w') or die("can't open file");
$data = x; // replace x with the xml from your ajax result !!!!!
fwrite($fh, $data);
fclose($fh);
【讨论】: