<?xml version="1.0" encoding="utf-8"?>
<s1 title="JSON"><p>JSON (JavaScript Object Notation) is a simple data-interchange format. Meaning it is an easy to use method to interchange data. </p>
<p><p>Contents</p>
<ol><li>
<link anchor="J">JSON Object</link></li>
<li>
<link anchor="j">json_encode</link></li>
</ol>
</li>
</ol>
<p> </p>
<p></p>
<s2 id="JSON Object" title="JSON Object">
<table><strong class="highlight"><![CDATA[]]></strong><tr><td><strong class="highlight"><![CDATA[]]></strong><p>Usage: </p>
</td><td><strong class="highlight"><![CDATA[]]></strong><p>ObjName = {Element1:Value1, Element2:Value2} </p>
</td></tr><tr><td><strong class="highlight"><![CDATA[]]></strong><p>Example: </p>
</td><td><strong class="highlight"><![CDATA[]]></strong><p>PlayerDetails = {Owner:&quot;NEAT&quot;, Group:1}<br/>
echo &quot;Player {PlayerDetails.Owner} is in group {PlayerDetails.Group}&quot; </p>
</td></tr></table><p>This method allows you to create and define a JSON Object and its elements. A JSON object is defined between braces {}. Within the braces you can define the elements of the objects well as the value of that element. </p>
<ul><li><source><![CDATA[NameOfJSONObject = { ElementName:"Value" }]]></source></li>
</ul>
<p>If you wanted to echo the above &quot;Value&quot; that was given to the element called &quot;ElementName&quot;, You can do this: </p>
<ul><li><source><![CDATA[echo NameOfJSONObject.ElementName]]></source></li>
</ul>
<p>The result of this would be: </p>
<ul><li><source><![CDATA[ (City Name) - Value
 (City Name) - Script stopped]]></source></li>
</ul>
<p><br/>
 </p>
<p></p>
</s2>
<s2 id="json_encode" title="json_encode">
<table><strong class="highlight"><![CDATA[]]></strong><tr><td><strong class="highlight"><![CDATA[]]></strong><p>Usage: </p>
</td><td><strong class="highlight"><![CDATA[]]></strong><p>json_encode() </p>
</td></tr><tr><td><strong class="highlight"><![CDATA[]]></strong><p>Example: </p>
</td><td><strong class="highlight"><![CDATA[]]></strong><p>JsonObj = {element:&quot;Value&quot;}<br/>
echo json_encode(JsonObj) </p>
</td></tr></table><p>json_encode() will allow you to encode a JSON object. </p>
<p>If you attempted to echo a JSON Object (the object itself, not an element within) it would output this: </p>
<ul><li><source><![CDATA[(City Name) - [object Object]]]></source></li>
</ul>
<p>This is due to it being encoded in the JSON language. To be able to get valid data from the object, json_encode is needed. </p>
<ul><li><source><![CDATA[thejson = {this:"that"}
echo json_encode(thejson)]]></source></li>
</ul>
<p>Outputs: </p>
<ul><li><source><![CDATA[ (City Name) - {"this":"that"}
 (City Name) - Script stopped]]></source></li>
</ul>
<p></p>

<br/>------------------------------------------------------------------------------<br/>
<p> <jump href="/wiki/CategoryFunctions">CategoryFunctions</jump> </p>
</s2></s1>