How to get data as json data

How to get data as json data

jquery json exmaple:
jQuery.getJSON( url, [ data ], [ success(data, textStatus, jqXHR) ] )
first save jquery.json
$(document).ready(function(){
 
$(‘#get-json-data’).live(‘click’, function(){
$.getJSON(‘json-data.php’, function(data) {
$(‘#showdata’).html(“<p>item1=”+data.item1+” item2=”+data.item2+” item3=”+data.item3+item4=”+data.item4+”item5=”+data.item5″</p>”);
});
});
});
 
Next 
save as json.php
json.php
< ?php
//now we will connect to database for getting the informations from database as json file
 
{
“item1”: “we are happy”,
“item2”: “they will go”,
“item3”: “-ok, we are ready”,
“item4”: “hi, juan”,
“item5”: “happy way to do that”
}
 
echo “{“;
echo “item1: “, json_encode($item1), “n”;
echo “item2: “, json_encode($item2), “n”;
echo “item3: “, json_encode($item3), “n”;
echo “item4: “, json_encode($item4), “n”;
echo “item5: “, json_encode($item5), “n”;
echo “}”;
?>
 
index.html
< !DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” ” http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd “>
<html xmlns=” http://www.w3.org/1999/xhtml “>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Request json test</title>
<script src=”http://code.jquery.com/jquery-1.5.js”></script>
<script src=”json-jquery.js” type=”text/javascript”></script>
</head>
<body>
<a href=”#” id=”get-json-data”>here we will get our josn data</a>
<div id=”showdata”></div>
</body>
</html>