tags:

views:

157

answers:

2

How do I install json in xampp server?

+4  A: 

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

samy
how to implement it in my xamp server.how i run json in my xamp server?
Ravi
It is a data format, you don't run it any more than you run a text document or a photo.
David Dorward
i use json for convert my sql data into xml.so how i convert it?
Ravi
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.
David Dorward
@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
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
my xamp version is 1.6.4
Ravi
@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
sorry my xamp version is 5.2.4
Ravi
thanks for reply.how i covert that json result into xml?
Ravi
convert json to xml: http://stackoverflow.com/questions/856833/is-there-some-way-to-convert-json-to-xml-in-php
Thariama
+1  A: 

Xampp is "shipped" with Apache, MySQL, PHP, Perl and support for JSON in PHP and Perl!

Json PHP

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);
Thariama
thanks.but how can i get array from query?
Ravi
i edited my post showing an example
Thariama
thanks for reply.i put json to xml code below to first step?
Ravi
you first get the data from the databse then you put everything into a json object and then you convert it to xml
Thariama
thanks for reply.i see the xml result in browser but xml file is not create.how to generate xml file.
Ravi
do you want it to save to disc?
Thariama
thanks lot......it working.
Ravi