﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-邪恶K线图-文章分类-Ajax</title><link>http://www.blogjava.net/zhazha1984/category/31146.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 02 May 2008 10:37:38 GMT</lastBuildDate><pubDate>Fri, 02 May 2008 10:37:38 GMT</pubDate><ttl>60</ttl><item><title>about JSON</title><link>http://www.blogjava.net/zhazha1984/articles/197715.html</link><dc:creator>邪恶K线图</dc:creator><author>邪恶K线图</author><pubDate>Fri, 02 May 2008 03:33:00 GMT</pubDate><guid>http://www.blogjava.net/zhazha1984/articles/197715.html</guid><wfw:comment>http://www.blogjava.net/zhazha1984/comments/197715.html</wfw:comment><comments>http://www.blogjava.net/zhazha1984/articles/197715.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zhazha1984/comments/commentRss/197715.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhazha1984/services/trackbacks/197715.html</trackback:ping><description><![CDATA[<font style="font-family: Verdana" size="2"><span style="font-family: Verdana"><span style="font-family: Verdana"><span style="font-size: 10pt"><span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><strong>JSON</strong> (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate.</span></span></span></span></span></span></span></span></span></span></span>
<p align="left"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt">JSON is built on two structures:</span></span></span></span></span></span></span></span></span></span></span></span></p>
<ul>
    <li>
    <div align="left"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt">A collection of name/value pairs. In various languages, this is realized as an <em>object</em>, record, struct, dictionary, hash table, keyed list, or associative array. </span></span></span></span></span></span></span></span></span></span></span></span></div>
    <li>
    <div align="left"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt">An ordered list of values. In most languages, this is realized as an <em>array</em>, vector, list, or sequence. </span></span></span></span></span></span></span></span></span></span></span></span></div>
    </li>
</ul>
<p align="left"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt">These are universal data structures. Virtually all modern programming languages support them in one form or another. It makes sense that a data format that is interchangable with programming languages also be based on these structures.</span></span></span></span></span></span></span></span></span></span></span></span></p>
<p align="left"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt">In JSON, they take on these forms:</span></span></span></span></span></span></span></span></span></span></span></span></p>
<p align="left"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-family: Verdana"><span style="font-size: 10pt"><span>An <em>object</em> is an unordered set of name/value pairs. An object begins with <tt>{</tt>&nbsp;<small>(left brace)</small> and ends with <tt>}</tt>&nbsp;<small>(right brace)</small>. Each name is followed by <tt>:</tt>&nbsp;<small>(colon)</small> and the name/value pairs are separated by <tt>,</tt>&nbsp;<small>(comma)</small>.</span></span></span></span><br />
<br />
<div align="center"><img height="113" alt="" src="http://www.blogjava.net/images/blogjava_net/zhazha1984/object.jpg" width="598" border="0" /></div>
<br />
<br />
<span style="font-size: 10pt; font-family: Verdana">An <em style="font-family: ">array</em> is an ordered collection of values. An array begins with <tt style="font-family: ">[</tt>&nbsp;<small style="font-family: ">(left bracket)</small> and ends with <tt style="font-family: ">]</tt>&nbsp;<small style="font-family: ">(right bracket)</small>. Values are separated by <tt style="font-family: ">,</tt>&nbsp;<small style="font-family: ">(comma)</small>.</span><br />
<br />
<div align="center"><img height="113" alt="" src="http://www.blogjava.net/images/blogjava_net/zhazha1984/array.jpg" width="598" border="0" /></div>
</span></span></span></span></span></span></span>
<p>&nbsp;</p>
<p align="left"><br />
<span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt">A <em>value</em> can be a <em>string</em> in double quotes, or a <em>number</em>, or <tt>true</tt> or <tt>false</tt> or <tt>null</tt>, or an <em>object</em> or an <em>array</em>. These structures can be nested.<br />
<br />
<div align="center"><img height="278" alt="" src="http://www.blogjava.net/images/blogjava_net/zhazha1984/value.jpg" width="598" border="0" /></div>
<br />
<br />
</span></span></span></span></span></span></span><font size="2"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt">There is an example show how to create a JSON object and operate it. <br />
<br />
</span></span>
<p>&nbsp;</p>
</span></span></span></span></span>
<div align="left">
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><img id="Codehighlighter1_20_607_Open_Image" onclick="this.style.display='none'; Codehighlighter1_20_607_Open_Text.style.display='none'; Codehighlighter1_20_607_Closed_Image.style.display='inline'; Codehighlighter1_20_607_Closed_Text.style.display='inline';" alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_20_607_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_20_607_Closed_Text.style.display='none'; Codehighlighter1_20_607_Open_Image.style.display='inline'; Codehighlighter1_20_607_Open_Text.style.display='inline';" alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif" align="top" /><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;showJSON()&nbsp;</span><span id="Codehighlighter1_20_607_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.blogjava.net/Images/dot.gif" /></span></span></span></span></span></span></span></span><span id="Codehighlighter1_20_607_Open_Text"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">{<br />
<img id="Codehighlighter1_37_269_Open_Image" onclick="this.style.display='none'; Codehighlighter1_37_269_Open_Text.style.display='none'; Codehighlighter1_37_269_Closed_Image.style.display='inline'; Codehighlighter1_37_269_Closed_Text.style.display='inline';" alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_37_269_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_37_269_Closed_Text.style.display='none'; Codehighlighter1_37_269_Open_Image.style.display='inline'; Codehighlighter1_37_269_Open_Text.style.display='inline';" alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">var</span><span style="color: #000000">&nbsp;student&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span id="Codehighlighter1_37_269_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.blogjava.net/Images/dot.gif" /></span></span></span></span></span></span></span></span><span id="Codehighlighter1_37_269_Open_Text"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">{<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">username</span><span style="color: #000000">"</span><span style="color: #000000">:</span><span style="color: #000000">"</span><span style="color: #000000">zhazha</span><span style="color: #000000">"</span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">,<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">sex</span><span style="color: #000000">"</span><span style="color: #000000">:</span><span style="color: #000000">"</span><span style="color: #000000">male</span><span style="color: #000000">"</span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">,<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">age</span><span style="color: #000000">"</span><span style="color: #000000">:</span><span style="color: #000000">21</span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">,<br />
<img id="Codehighlighter1_102_142_Open_Image" onclick="this.style.display='none'; Codehighlighter1_102_142_Open_Text.style.display='none'; Codehighlighter1_102_142_Closed_Image.style.display='inline'; Codehighlighter1_102_142_Closed_Text.style.display='inline';" alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_102_142_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_102_142_Closed_Text.style.display='none'; Codehighlighter1_102_142_Open_Image.style.display='inline'; Codehighlighter1_102_142_Open_Text.style.display='inline';" alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">address</span><span style="color: #000000">"</span><span style="color: #000000">:</span><span id="Codehighlighter1_102_142_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.blogjava.net/Images/dot.gif" /></span><span id="Codehighlighter1_102_142_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">"</span><span style="color: #000000">city</span><span style="color: #000000">"</span><span style="color: #000000">:</span><span style="color: #000000">"</span><span style="color: #000000">guangzhou</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">postcode</span><span style="color: #000000">"</span><span style="color: #000000">:</span><span style="color: #000000">"</span><span style="color: #000000">510006</span><span style="color: #000000">"</span><span style="color: #000000">}</span></span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">,<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">selectedCourse</span><span style="color: #000000">"</span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">:[<br />
<img id="Codehighlighter1_169_210_Open_Image" onclick="this.style.display='none'; Codehighlighter1_169_210_Open_Text.style.display='none'; Codehighlighter1_169_210_Closed_Image.style.display='inline'; Codehighlighter1_169_210_Closed_Text.style.display='inline';" alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_169_210_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_169_210_Closed_Text.style.display='none'; Codehighlighter1_169_210_Open_Image.style.display='inline'; Codehighlighter1_169_210_Open_Text.style.display='inline';" alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_169_210_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.blogjava.net/Images/dot.gif" /></span><span id="Codehighlighter1_169_210_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">"</span><span style="color: #000000">cid</span><span style="color: #000000">"</span><span style="color: #000000">:</span><span style="color: #000000">"</span><span style="color: #000000">cs001</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">course</span><span style="color: #000000">"</span><span style="color: #000000">:</span><span style="color: #000000">"</span><span style="color: #000000">AI</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">score</span><span style="color: #000000">"</span><span style="color: #000000">:</span><span style="color: #000000">89</span><span style="color: #000000">}</span></span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">,<br />
<img id="Codehighlighter1_216_262_Open_Image" onclick="this.style.display='none'; Codehighlighter1_216_262_Open_Text.style.display='none'; Codehighlighter1_216_262_Closed_Image.style.display='inline'; Codehighlighter1_216_262_Closed_Text.style.display='inline';" alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_216_262_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_216_262_Closed_Text.style.display='none'; Codehighlighter1_216_262_Open_Image.style.display='inline'; Codehighlighter1_216_262_Open_Text.style.display='inline';" alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_216_262_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.blogjava.net/Images/dot.gif" /></span><span id="Codehighlighter1_216_262_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">"</span><span style="color: #000000">cid</span><span style="color: #000000">"</span><span style="color: #000000">:</span><span style="color: #000000">"</span><span style="color: #000000">cs002</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">course</span><span style="color: #000000">"</span><span style="color: #000000">:</span><span style="color: #000000">"</span><span style="color: #000000">Network</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">score</span><span style="color: #000000">"</span><span style="color: #000000">:</span><span style="color: #000000">92</span><span style="color: #000000">}</span></span></span></span></span></span></span></span></span><span style="color: #000000"><br />
<span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">;<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;alert(student.username&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;student.sex&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">&nbsp;student.age);<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;alert(student.address.city&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">&nbsp;student.address.postcode);<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;alert(student.selectedCourse[</span><span style="color: #000000">1</span><span style="color: #000000">].course&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;student.selectedCourse[</span><span style="color: #000000">1</span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">].score);<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;student.selectedCourse[</span><span style="color: #000000">1</span><span style="color: #000000">].score&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">100</span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">;<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;alert(student.selectedCourse[</span><span style="color: #000000">1</span><span style="color: #000000">].course&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;student.selectedCourse[</span><span style="color: #000000">1</span></span></span></span></span></span></span></span><span style="color: #000000"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt">].score);<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></span></span></span></span></span></span></span></div>
</div>
</font></font><font size="2">
<p align="left"><br />
<span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt">To convert a JSON text into an object, use the eval() function. eval() invokes the JavaScript compiler. Since JSON is a proper subset of JavaScript, the compiler will correctly parse the text and produce an object structure. <br />
<br />
<font size="2">Your can use eval() function to pares JSON text to JSON Object. </font><br />
<br />
<font size="2">For example: </font><br />
<br />
</span></span></p>
</span></span></span></span></span>
<div align="left">
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><img id="Codehighlighter1_22_506_Open_Image" onclick="this.style.display='none'; Codehighlighter1_22_506_Open_Text.style.display='none'; Codehighlighter1_22_506_Closed_Image.style.display='inline'; Codehighlighter1_22_506_Closed_Text.style.display='inline';" alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_22_506_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_22_506_Closed_Text.style.display='none'; Codehighlighter1_22_506_Open_Image.style.display='inline'; Codehighlighter1_22_506_Open_Text.style.display='inline';" alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif" align="top" /><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;TextToJSON()&nbsp;</span><span id="Codehighlighter1_22_506_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.blogjava.net/Images/dot.gif" /></span></span></span></span></span></span></span></span><span id="Codehighlighter1_22_506_Open_Text"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">{<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">var</span><span style="color: #000000">&nbsp;studentText&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">{'username':'zhazha','sex':'male','age':21,</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span></span></span></span></span></span></span></span><span style="color: #000000"><br />
<span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">"</span><span style="color: #000000">'address':{'city':'guangzhou',&nbsp;'postcode':'510006'},</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span></span></span></span></span></span></span></span><span style="color: #000000"><br />
<span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">"</span><span style="color: #000000">'selectedCourse':[{'cid':'cs001',&nbsp;'course':'AI',&nbsp;'score':89},</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span></span></span></span></span></span></span></span><span style="color: #000000"><br />
<span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">"</span><span style="color: #000000">{'cid':'cs002',&nbsp;'course':'Network',&nbsp;'score':92}]}</span><span style="color: #000000">"</span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">;<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">var</span><span style="color: #000000">&nbsp;obj1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;eval('('&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;studentText&nbsp;</span><span style="color: #000000">+</span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">&nbsp;')');<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;alert(obj1.username&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;obj1.sex&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">&nbsp;obj1.age);<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;alert(obj1.address.city&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">&nbsp;obj1.address.postcode);<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;alert(obj1.selectedCourse[</span><span style="color: #000000">1</span><span style="color: #000000">].course&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;obj1.selectedCourse[</span><span style="color: #000000">1</span></span></span></span></span></span></span></span><span style="color: #000000"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt">].score);<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></span></span></span></span></span></span></span></div>
</div>
</font>
<p align="left"><br />
<span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><font size="2">A JSON stringifier goes in the opposite direction, converting JavaScript data structures into JSON text. JSON does not support cyclic data structures, so be careful to not give cyclical structures to the JSON stringifier. </font><br />
<br />
<font size="2">(PS: Please download </font></span></span></span></span></span></span></span><a href="http://www.json.org/json2.js" target="_blank"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt">json2.js</span></span></span></span></span></span></span></a><wbr><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><font size="2"> before using the JSON stringifier)</font><br />
<br />
<font size="2">For example: </font><br />
<br />
</span></span></p>
</span></span></span></span></span>
<div align="left">
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><img id="Codehighlighter1_22_106_Open_Image" onclick="this.style.display='none'; Codehighlighter1_22_106_Open_Text.style.display='none'; Codehighlighter1_22_106_Closed_Image.style.display='inline'; Codehighlighter1_22_106_Closed_Text.style.display='inline';" alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_22_106_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_22_106_Closed_Text.style.display='none'; Codehighlighter1_22_106_Open_Image.style.display='inline'; Codehighlighter1_22_106_Open_Text.style.display='inline';" alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif" align="top" /><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;JSONToText()&nbsp;</span><span id="Codehighlighter1_22_106_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.blogjava.net/Images/dot.gif" /></span></span></span></span></span></span></span></span><span id="Codehighlighter1_22_106_Open_Text"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">{<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">var</span><span style="color: #000000">&nbsp;person&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Person(</span><span style="color: #000000">"</span><span style="color: #000000">zhazha</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">male</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">21</span><span style="color: #000000">"</span></span></span></span></span></span></span></span><span style="color: #000000"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt">);<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;alert(JSON.stringify(person));<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></span></span></span></span></span></span></span><span style="color: #000000"><br />
<span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align="top" /><br />
<img id="Codehighlighter1_145_208_Open_Image" onclick="this.style.display='none'; Codehighlighter1_145_208_Open_Text.style.display='none'; Codehighlighter1_145_208_Closed_Image.style.display='inline'; Codehighlighter1_145_208_Closed_Text.style.display='inline';" alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_145_208_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_145_208_Closed_Text.style.display='none'; Codehighlighter1_145_208_Open_Image.style.display='inline'; Codehighlighter1_145_208_Open_Text.style.display='inline';" alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gif" align="top" /></span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;Person(username,&nbsp;sex,&nbsp;age)&nbsp;</span><span id="Codehighlighter1_145_208_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.blogjava.net/Images/dot.gif" /></span></span></span></span></span></span></span></span><span id="Codehighlighter1_145_208_Open_Text"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">{<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.username&nbsp;</span><span style="color: #000000">=</span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">&nbsp;username;<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.sex&nbsp;</span><span style="color: #000000">=</span></span></span></span></span></span></span></span><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #000000">&nbsp;sex;<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.age&nbsp;</span><span style="color: #000000">=</span></span></span></span></span></span></span></span><span style="color: #000000"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="font-family: Verdana"><span style="font-size: 10pt"><span style="color: #333333"><span style="font-family: Verdana"><span style="font-size: 10pt">&nbsp;age;<br />
<img alt="" src="http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></span></span></span></span></span></span></span></div>
</div>
<img src ="http://www.blogjava.net/zhazha1984/aggbug/197715.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhazha1984/" target="_blank">邪恶K线图</a> 2008-05-02 11:33 <a href="http://www.blogjava.net/zhazha1984/articles/197715.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>