diff options
Diffstat (limited to 'doc/files/lib/json_rb.html')
-rw-r--r-- | doc/files/lib/json_rb.html | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/doc/files/lib/json_rb.html b/doc/files/lib/json_rb.html new file mode 100644 index 0000000..545e285 --- /dev/null +++ b/doc/files/lib/json_rb.html @@ -0,0 +1,156 @@ +<?xml version="1.0" encoding="utf-8"?> +<!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" xml:lang="en" lang="en"> +<head> + <title>json.rb</title> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" /> +<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" /> +<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" /> +<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script> +<script src="../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script> +<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script> +<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script> + +</head> + +<body> + <div class="banner"> + + <h1> + json.rb + </h1> + <ul class="files"> + <li>lib/json.rb</li> + <li>Last modified: 2012-09-14 17:53:45 +0200</li> + </ul> + </div> + + <div id="bodyContent"> + <div id="content"> + + <div class="description"> + +<h1 id="label-JavaScript+Object+Notation+%28JSON%29">JavaScript Object Notation (<a href="../../classes/JSON.html">JSON</a>)</h1> + +<p><a href="../../classes/JSON.html">JSON</a> is a lightweight +data-interchange format. It is easy for us humans to read and write. Plus, +equally simple for machines to generate or parse. <a +href="../../classes/JSON.html">JSON</a> is completely language agnostic, +making it the ideal interchange format.</p> + +<p>Built on two universally available structures:</p> + +<pre>1. A collection of name/value pairs. Often referred to as an _object_, hash table, record, struct, keyed list, or associative array. +2. An ordered list of values. More commonly called an _array_, vector, sequence or list.</pre> + +<p>To read more about <a href="../../classes/JSON.html">JSON</a> visit: <a +href="http://json.org">json.org</a></p> + +<h2 id="label-Parsing+JSON">Parsing <a href="../../classes/JSON.html">JSON</a></h2> + +<p>To parse a <a href="../../classes/JSON.html">JSON</a> string received by +another application or generated within your existing application:</p> + +<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'json'</span> + +<span class="ruby-identifier">my_hash</span> = <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">'{"hello": "goodbye"}'</span>) +<span class="ruby-identifier">puts</span> <span class="ruby-identifier">my_hash</span>[<span class="ruby-string">"hello"</span>] =<span class="ruby-operator">></span> <span class="ruby-string">"goodbye"</span> +</pre> + +<p>Notice the extra quotes <code>''</code> around the hash notation. Ruby +expects the argument to be a string and can’t convert objects like a hash +or array.</p> + +<p>Ruby converts your string into a hash</p> + +<h2 id="label-Generating+JSON">Generating <a href="../../classes/JSON.html">JSON</a></h2> + +<p>Creating a <a href="../../classes/JSON.html">JSON</a> string for +communication or serialization is just as simple.</p> + +<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'json'</span> + +<span class="ruby-identifier">my_hash</span> = {:<span class="ruby-identifier">hello</span> =<span class="ruby-operator">></span> <span class="ruby-string">"goodbye"</span>} +<span class="ruby-identifier">puts</span> <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">generate</span>(<span class="ruby-identifier">my_hash</span>) =<span class="ruby-operator">></span> <span class="ruby-string">"{\"hello\":\"goodbye\"}"</span> +</pre> + +<p>Or an alternative way:</p> + +<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'json'</span> +<span class="ruby-identifier">puts</span> {:<span class="ruby-identifier">hello</span> =<span class="ruby-operator">></span> <span class="ruby-string">"goodbye"</span>}.<span class="ruby-identifier">to_json</span> =<span class="ruby-operator">></span> <span class="ruby-string">"{\"hello\":\"goodbye\"}"</span> +</pre> + +<p><code>JSON.generate</code> only allows objects or arrays to be converted to +<a href="../../classes/JSON.html">JSON</a> syntax. <code>to_json</code>, +however, accepts many Ruby classes even though it acts only as a method for +serialization:</p> + +<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'json'</span> + +<span class="ruby-value">1</span>.<span class="ruby-identifier">to_json</span> =<span class="ruby-operator">></span> <span class="ruby-string">"1"</span> +</pre> + + </div> + + + + + <!-- File only: requires --> + <div class="sectiontitle">Required Files</div> + <ul> + + <li>json/common</li> + + <li>json/version</li> + + <li>json/ext</li> + + <li>json/pure</li> + + </ul> + + + + + + + + + <!-- Namespace --> + <div class="sectiontitle">Namespace</div> + <ul> + + <li> + <span class="type">MODULE</span> + <a href="../../classes/JSON.html">JSON</a> + </li> + + </ul> + + + + + + + + + + + + + + + + + + + + + + <!-- Methods --> + </div> + </div> + </body> +</html>
\ No newline at end of file |