How do I install json in xampp server?
-
1do you mean a php extension ??? – jknair Oct 05 '10 at 06:46
-
2Ravi: Did you know: You can edit your question, so include this information in your question to improve it. Another hint that might help you get better votes and more answers: Go to your old questions and *accept* the answer to each that helped you most (by clicking on the checkmark besides it. – chiccodoro Oct 05 '10 at 07:03
2 Answers
Json is a format; you don't install it, you implement it.
If you want to use the json format in your php website, there's an extension that provides functions you can use to encode data in a json format.
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 version of xampp (windows install), it's ok to use the methods directly

- 14,832
- 2
- 54
- 82
-
how to implement it in my xamp server.how i run json in my xamp server? – user824984 Oct 05 '10 at 06:48
-
2It is a data format, you don't run it any more than you run a text document or a photo. – Quentin Oct 05 '10 at 06:49
-
-
You can't use JSON to convert SQL data into XML (since it is, as might have been mentioned already, a data format and not a programming language). You could, in theory, use it as an intermediary format, but that sounds like a waste of time. – Quentin Oct 05 '10 at 06:55
-
@Ravi: you write a php script to convert data into json format which will then be sent to javascript to process, check the php function json_encode() for a reference – Michael Mao Oct 05 '10 at 06:59
-
samy: Your answer is great (+1), it covers both the correction of Ravi's understanding on what JSON is as well as tips concerning the add-in he seems to be speaking of and contains many helpful links. However your second sentence you added is a little bit confusing because you don't tell that you start to speak about an add-in now. You might want to add some words there, e.g.: "If you're speaking about the JSON add-in: Depending on your version..." – chiccodoro Oct 05 '10 at 07:00
-
-
1@chiccodoro: thanks for the advice, i edited the answer. @ravi: your install of xampp contains two versions of php (4.4.7 and 5.2.4); you must use the 5.2.4 to benefit from the bundled json extension. If you use the 4.2.7 version, either change versions or install the extension following the link i posted – samy Oct 05 '10 at 07:19
-
-
-
1convert json to xml: http://stackoverflow.com/questions/856833/is-there-some-way-to-convert-json-to-xml-in-php – Thariama Oct 05 '10 at 07:40
Xampp is "shipped" with Apache, MySQL, PHP, Perl and support for JSON in PHP and Perl!
Json Perl: JSON::to_json(hash);
Simple PHP example from 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:
<?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.
Edit3: If you want to save the xml file to disc use
$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);
-
1
-
-
-
you first get the data from the databse then you put everything into a json object and then you convert it to xml – Thariama Oct 05 '10 at 09:10
-
thanks for reply.i see the xml result in browser but xml file is not create.how to generate xml file. – user824984 Oct 05 '10 at 09:48
-