我如何在 xampp 服务器中安装 json?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3861354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how do i install json in xampp server?
提问by user824984
How do I install json in xampp server?
如何在 xampp 服务器中安装 json?
回答by samy
Json is a format; you don't install it, you implement it.
Json 是一种格式;你不安装它,你实现它。
If you want to use the json format in your php website, there's an extension that provides functionsyou can use to encode data in a json format.
如果你想使用JSON格式在你的PHP的网站,还有的是提供了一个扩展功能,您可以使用一个JSON格式的编码数据。
To install or use the extension, please see the installation page; depending on your version of php you may have the json extension already bundled with xampp. If you've got the latest versionof xampp (windows install), it's ok to use the methods directly
要安装或使用扩展程序,请参阅安装页面;根据您的 php 版本,您可能已经将 json 扩展与 xampp 捆绑在一起。如果你有最新版本的xampp(windows安装),直接使用方法就可以了
回答by Thariama
Xampp is "shipped" with Apache, MySQL, PHP, Perl and support for JSON in PHP and Perl!
Xampp 随 Apache、MySQL、PHP、Perl 一起“发货”,并支持 PHP 和 Perl 中的 JSON!
Json Perl:JSON::to_json(hash);
杰森珀尔:JSON::to_json(hash);
Simple PHP examplefrom php.net
<?php
$arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);
echo json_encode($arr);
?>
EDIT:Second example showing how to json_encode() a mysql query result:
编辑:显示如何 json_encode() mysql 查询结果的第二个示例:
<?php
$sth = mysql_query("SELECT ...");
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
?>
EDIT 2:You are then able to convert JSON to XML using one of the described methods from this stackoverflow question.
编辑 2:然后您可以使用此 stackoverflow question 中描述的方法之一将 JSON 转换为 XML 。
Edit3:If you want to save the xml file to disc use
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);

