<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>DigiMantra &#187; JSON</title>
	<atom:link href="http://www.digimantra.com/category/technology/json/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.digimantra.com</link>
	<description>Technology tips for all</description>
	<lastBuildDate>Fri, 16 Jul 2010 06:28:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<atom:link rel='hub' href='http://www.digimantra.com/?pushpress=hub'/>
		<item>
		<title>Using JSON with PHP, javascript &#124;Tutorial 1</title>
		<link>http://www.digimantra.com/technology/using-json-with-php-javascript-tutorial-1/</link>
		<comments>http://www.digimantra.com/technology/using-json-with-php-javascript-tutorial-1/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 14:07:14 +0000</pubDate>
		<dc:creator>Sachin Khosla</dc:creator>
				<category><![CDATA[JSON]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://realin.co.in/?p=153</guid>
		<description><![CDATA[Hi Programmers, Heard about JSON, and wandering how the hell you gonna implement it with PHP. And why would one use JSON when you have ajax and other alternatives. Well first of to understand JSON, i would recommend you to go through the JSON introduction part which i covered in my earlier post. Now coming [...]


Related posts:<ol><li><a href='http://www.digimantra.com/technology/javascript/check-username-availability-validation-ajaxphp/' rel='bookmark' title='Permanent Link: Check username availability and validation using ajax,php'>Check username availability and validation using ajax,php</a></li>
<li><a href='http://www.digimantra.com/technology/javascript/is-object-function-for-javascript/' rel='bookmark' title='Permanent Link: is_object function for javascript'>is_object function for javascript</a></li>
<li><a href='http://www.digimantra.com/technology/what-exactly-json-is/' rel='bookmark' title='Permanent Link: What exactly JSON is ?'>What exactly JSON is ?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Hi Programmers,</p>
<p>Heard about JSON, and wandering how the hell you gonna implement it with PHP. And why would one use JSON when you have ajax and other alternatives. Well first of to understand JSON, i would recommend you to go through the <a href="http://www.digimantra.com/2008/09/what-exactly-json-is/" target="_blank">JSON introduction part</a> which i covered in my earlier post.</p>
<p>Now coming straight to the point, i am gonna cover the following things in this post</p>
<p>1) Prepare JSON string using php using <a rel="nofollow" target="_blank" href="http://www.php.net/json_encode" target="_blank">json_encode()</a> and send it to client side</p>
<p>2) Make the object from JSON string using <a rel="nofollow" target="_blank" href="http://www.w3schools.com/jsref/jsref_eval.asp" target="_blank">eval()</a></p>
<p>3) Use this Object at client side using javscript.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$array</span><span style="color: #339933;">=</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>	a<span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;One&quot;</span><span style="color: #339933;">,</span>
				b<span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;Two&quot;</span><span style="color: #339933;">,</span>
				c<span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;three&quot;</span>
			<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$json</span><span style="color: #339933;">=</span><span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The above php code, encodes an array of php into JSON string. That means this string can be sent to the client side and is a useful data for us. This data can be anything you like. You can pull this data from the database and then can manipulate at the client side as required using javascript. The function json_encode, encodes the given array in the JSON format. I have stored the string in the varibal $json and then embeded in the html using hidden field, shown below.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
&lt;title&gt; JSON with Realin&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
function parseMe(){
var json=document.getElementById(&quot;json_text&quot;).value;
&nbsp;
var obj=eval('('+json+')');
document.createElement(&quot;ul&quot;);
for(val in obj){
	alert(obj[val]);
}
&nbsp;
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&nbsp;
&lt;form&gt;
&lt;input type=&quot;hidden&quot; id=&quot;json_text&quot; value='&lt;?php echo $json; ?&gt;' /&gt;
&lt;input type='button' value=&quot;parse&quot; onclick=&quot;parseMe();&quot; /&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>The above HTML has the value of that JSON string in the hidden field. If you are using some sorta template engine then you can assign this string the variable used in your template engine. For example in fast template i will do, $templateobject->assign(&#8216;JSON_OBJ&#8217;,$json);</p>
<p>This data can be used as you want to, very soon i will post a blog entry which lets you sort the table data using this JSON data.</p>
<p>Leave comments,</p>
<p>Cheers !!</p>
<p>Realin !</p>


<p>Related posts:<ol><li><a href='http://www.digimantra.com/technology/javascript/check-username-availability-validation-ajaxphp/' rel='bookmark' title='Permanent Link: Check username availability and validation using ajax,php'>Check username availability and validation using ajax,php</a></li>
<li><a href='http://www.digimantra.com/technology/javascript/is-object-function-for-javascript/' rel='bookmark' title='Permanent Link: is_object function for javascript'>is_object function for javascript</a></li>
<li><a href='http://www.digimantra.com/technology/what-exactly-json-is/' rel='bookmark' title='Permanent Link: What exactly JSON is ?'>What exactly JSON is ?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.digimantra.com/technology/using-json-with-php-javascript-tutorial-1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>What exactly JSON is ?</title>
		<link>http://www.digimantra.com/technology/what-exactly-json-is/</link>
		<comments>http://www.digimantra.com/technology/what-exactly-json-is/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 16:52:37 +0000</pubDate>
		<dc:creator>Sachin Khosla</dc:creator>
				<category><![CDATA[JSON]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://realin.co.in/?p=46</guid>
		<description><![CDATA[Heard the term JSON and wondered what it is ? Well you should be its growing up these days and at first it seems like it is just another framework like jquery or some library in javascript. But let me tell you its something you might want to use more often What does it stand [...]


Related posts:<ol><li><a href='http://www.digimantra.com/technology/using-json-with-php-javascript-tutorial-1/' rel='bookmark' title='Permanent Link: Using JSON with PHP, javascript |Tutorial 1'>Using JSON with PHP, javascript |Tutorial 1</a></li>
<li><a href='http://www.digimantra.com/interview-or-q-a/php-interview-beginners-fresher/' rel='bookmark' title='Permanent Link: PHP Interview for Beginners/Novice/Freshers | Part 1'>PHP Interview for Beginners/Novice/Freshers | Part 1</a></li>
<li><a href='http://www.digimantra.com/technology/php/get-data-from-a-url-using-curl-php/' rel='bookmark' title='Permanent Link: Get data from a URL using cURL PHP'>Get data from a URL using cURL PHP</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Heard the term JSON and wondered what it is ? Well you should be its growing up these days and at first it seems like it is just another framework like jquery or some library in javascript. But let me tell you its something you might want to use more often <img src='http://www.digimantra.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' title="What exactly JSON is ?" /> </p>
<p><a href="http://www.digimantra.com/blog/wp-content/uploads/2008/09/json160.gif"><img class="alignright size-full wp-image-47" title="json160" src="http://www.digimantra.com/blog/wp-content/uploads/2008/09/json160.gif" alt="json160 What exactly JSON is ?" width="97" height="97" /></a></p>
<p><strong><span style="color: #000080;"><span style="color: #0000ff;">What does it stand for ?</span></span></strong></p>
<p><strong>J</strong>ava<strong>S</strong>cript <strong>O</strong>ject <strong>N</strong>otation</p>
<p><strong><span style="color: #0000ff;">What does it do ? </span></strong></p>
<p>It is a collection of name value pairs, and is easily readable by human and machines. It is completely machine/language independent. It more like XML but is very different in syntax.</p>
<p><strong>A snippet from JSON code</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;realin&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #3366CC;">&quot;blog&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>
&nbsp;
<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Your Tech Dose&quot;</span><span style="color: #339933;">,</span>
&nbsp;
<span style="color: #3366CC;">&quot;url&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://realin.co.in&quot;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Sachin Khosla&quot;</span><span style="color: #339933;">,</span>
&nbsp;
<span style="color: #3366CC;">&quot;profession&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;software engineer&quot;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
&nbsp;
<span style="color: #3366CC;">&quot;belongs&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>
&nbsp;
<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;place&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Delhi/India&quot;</span><span style="color: #339933;">,</span>
&nbsp;
<span style="color: #3366CC;">&quot;Status&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Citizen&quot;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p><span id="more-46"></span></p>
<p>So you see you can easily understand what this is all about. If we extract the symbols then there are 4 basic symbols used in here <span style="color: #3366ff;"><strong>Squiggles, Square,colons and comma</strong></span></p>
<p><span style="color: #3366ff;"><strong>Squiggles (</strong></span><strong> {<span style="color: #3366ff;"> )</span> </strong>acts as container</p>
<p><span style="color: #3366ff;"><strong>Square (<span style="color: #000000;"> [</span> ) </strong><span style="color: #000000;">as usual holds arrays</span></span></p>
<p><span style="color: #3366ff;"><strong>colons (</strong></span><span style="color: #3366ff;"><strong> </strong></span>: <span style="color: #3366ff;"><strong>)</strong></span> seperates the name value pair</p>
<p><span style="color: #3366ff;"><strong>comma (</strong></span><span style="color: #3366ff;"><strong> </strong></span>, <span style="color: #3366ff;"><strong>) </strong></span>seperates the array values</p>
<p><span style="color: #ff6600;"><strong>XML and JSON are they alike ? </strong></span></p>
<p>Well i must say yes, and reason being :</p>
<ol>
<li>Both them are human readable and descriptive as in what they are.</li>
<li>Both have a hierarchal descriptive order</li>
<li>Both are language independent</li>
<li>Both can be used with AJAX</li>
</ol>
<p><span style="color: #ff6600;"><strong>Did someone say XML and JSON are different ?</strong></span></p>
<p>XML have angular bracket representation like html</p>
<p>XML can be tedious, where as writing JSON is like a regular code writing</p>
<p>&#8230;. can&#8217;t think more of it for now <img src='http://www.digimantra.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' title="What exactly JSON is ?" /> </p>
<p><strong><span style="color: #3366ff;">Is it client or server side ?<br />
</span></strong>PHP supports <a rel="nofollow" target="_blank" href="http://www.php.net/json" target="_blank">JSON extension</a> and many other language too, you can find a list <a rel="nofollow" target="_blank" href="http://www.php.net/json" target="_blank">here<br />
</a></p>
<p>And ofcourse it is supported at client side</p>
<p><strong><span style="color: #3366ff;">Here we end ..</span></strong></p>
<p>So why you should choose JSON over XML, well i must say that JSON is quicker than XML because you avoid writing handwritten XML.</p>
<p>Cheers !!</p>
<p>Realin !</p>


<p>Related posts:<ol><li><a href='http://www.digimantra.com/technology/using-json-with-php-javascript-tutorial-1/' rel='bookmark' title='Permanent Link: Using JSON with PHP, javascript |Tutorial 1'>Using JSON with PHP, javascript |Tutorial 1</a></li>
<li><a href='http://www.digimantra.com/interview-or-q-a/php-interview-beginners-fresher/' rel='bookmark' title='Permanent Link: PHP Interview for Beginners/Novice/Freshers | Part 1'>PHP Interview for Beginners/Novice/Freshers | Part 1</a></li>
<li><a href='http://www.digimantra.com/technology/php/get-data-from-a-url-using-curl-php/' rel='bookmark' title='Permanent Link: Get data from a URL using cURL PHP'>Get data from a URL using cURL PHP</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.digimantra.com/technology/what-exactly-json-is/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
