JSON-lib框架教程,转换JSON、XML不再困难

fmms 9年前
     <div id="cnblogs_post_body">     <p>Json-lib可以将Java对象转成json格式的字符串,也可以将Java对象转换成xml格式的文档,同样可以将json字符串转换成Java对象或是将xml字符串转换成Java对象。 </p>     <p><b>一、 </b><b>准备工作</b><b> </b> </p>     <p><b> </b></p>     <p>1、 首先要去官方下载json-lib工具包 </p>     <p>下载地址: </p>     <p><a href="/misc/goto?guid=4959517669038359018">http://sourceforge.net/projects/json-lib/files/json-lib/json-lib-2.4/</a> </p>     <p>目前最新的是2.4的版本,本示例中使用的是v2.3;json-lib还需要以下依赖包: </p>     <p>jakarta commons-lang 2.5 </p>     <p>jakarta commons-beanutils 1.8.0 </p>     <p>jakarta commons-collections 3.2.1 </p>     <p>jakarta commons-logging 1.1.1 </p>     <p>ezmorph 1.0.6 </p>     <p>官方网址:<a href="/misc/goto?guid=4959499360114181159">http://json-lib.sourceforge.net/</a> </p>     <p>然后在工程中添加如下jar包: </p>     <p><a href="https://simg.open-open.com/show/235d42dc92fac395ca161dd1479f88b7.jpg"><img title="d4.jpg" border="0" alt="d4.jpg" src="https://simg.open-open.com/show/8331d34c7fb2b7fac2804384f0fffed3.jpg" width="191" height="109" /></a> </p>     <p>当然你也可以用2.4的json-lib库 </p>     <p>你可以在这里看看官方提供的示例: </p>     <p><a href="/misc/goto?guid=4959517669162820993">http://json-lib.sourceforge.net/usage.html</a> </p>     <p>由于本次介绍的示例需要junit工具,所以你还需要添加junit的jar文件,版本是4.8.2版本的,下载地址:<a href="/misc/goto?guid=4959517669249980218">https://github.com/KentBeck/junit/downloads</a> </p>     <p>如果你还不了解JSON是什么?那么你应该可以看看<a href="/misc/goto?guid=4959500829331297171">http://www.json.org/json-zh.html</a> </p>     <p>2、 要转换的JavaBean的代码如下: </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">package</span> com.hoo.entity;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> Student {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">int</span> id;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> String name;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> String email;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> String address;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> Birthday birthday;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//setter、getter</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">public</span> String toString() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">this</span>.name + <span style="color:#006080;">"#"</span> + <span style="color:#0000ff;">this</span>.id + <span style="color:#006080;">"#"</span> + <span style="color:#0000ff;">this</span>.address + <span style="color:#006080;">"#"</span> + <span style="color:#0000ff;">this</span>.birthday + <span style="color:#006080;">"#"</span> + <span style="color:#0000ff;">this</span>.email;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>      </div>     </div>     <p>Birthday.java </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">package</span> com.hoo.entity;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> Birthday {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> String birthday;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">public</span> Birthday(String birthday) {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">super</span>();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">this</span>.birthday = birthday;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//setter、getter</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">public</span> Birthday() {}</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    @Override</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">public</span> String toString() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">this</span>.birthday;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>      </div>     </div>     <p>注意,上面的getter、setter方法省略了,自己构建下。 </p>     <p>3、 新建JsonlibTest测试类,基本代码如下: </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">package</span> com.hoo.test;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.lang.reflect.InvocationTargetException;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.ArrayList;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.Collection;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.Date;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.HashMap;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.Iterator;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.List;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.Map;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.Set;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> net.sf.json.JSON;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> net.sf.json.JSONArray;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> net.sf.json.JSONFunction;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> net.sf.json.JSONObject;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> net.sf.json.JSONSerializer;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> net.sf.json.JsonConfig;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> net.sf.json.processors.JsonValueProcessor;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> net.sf.json.util.PropertyFilter;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> net.sf.json.xml.XMLSerializer;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.apache.commons.beanutils.PropertyUtils;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.junit.After;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.junit.Before;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.junit.Test;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.hoo.entity.Birthday;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.hoo.entity.Student;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b> 用json-lib转换java对象到JSON字符串</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * 读取json字符串到java对象,序列化jsonObject到xml</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * json-lib-version: json-lib-2.3-jdk15.jar</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * 依赖包: </span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * commons-beanutils.jar</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * commons-collections-3.2.jar</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * ezmorph-1.0.3.jar</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * commons-lang.jar</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * commons-logging.jar</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate Nov 28, 2010 2:28:39 PM</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @file JsonlibTest.java</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @package com.hoo.test</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @project WebHttpUtils</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @blog http://blog.csdn.net/IBM_hoojo</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @email hoojo_@126.com</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @version 1.0</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@SuppressWarnings({ <span style="color:#006080;">"deprecation"</span>, <span style="color:#006080;">"unchecked"</span> })</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> JsonlibTest {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> JSONArray jsonArray = null;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> JSONObject jsonObject = null;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> Student bean = null;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    @Before</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> init() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        jsonArray = <span style="color:#0000ff;">new</span> JSONArray(); </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        jsonObject = <span style="color:#0000ff;">new</span> JSONObject(); </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean = <span style="color:#0000ff;">new</span> Student();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setAddress(<span style="color:#006080;">"address"</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setEmail(<span style="color:#006080;">"email"</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setId(1);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setName(<span style="color:#006080;">"haha"</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Birthday day = <span style="color:#0000ff;">new</span> Birthday();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        day.setBirthday(<span style="color:#006080;">"2010-11-22"</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setBirthday(day);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    @After</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> destory() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        jsonArray = null;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        jsonObject = null;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean = null;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.gc();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">final</span> <span style="color:#0000ff;">void</span> fail(String string) {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.out.println(string);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">final</span> <span style="color:#0000ff;">void</span> failRed(String string) {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.err.println(string);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>      </div>     </div>     <p>上面的init会在每个方法之前运行,destory会在每个方法完成后执行。分别用到了junit的@Before、@After注解,如果你对junit的这些注解不是很了解,可以看看junit官方的测试用例的example和doc; </p>     <p>JSONObject是将Java对象转换成一个json的Object形式,JSONArray是将一个Java对象转换成json的Array格式。 </p>     <p>那什么是json的Object形式、Array形式? </p>     <p>用通俗易懂的方法将,所谓的json的Object形式就是一个花括号里面存放的如JavaMap的键值对,如:{name:’hoojo’, age: 24}; </p>     <p>那么json的Array形式呢? </p>     <p>就是中括号,括起来的数组。如:[ ‘json’, true, 22]; </p>     <p>如果你还想了解更多json方面的知识,请看:<a href="/misc/goto?guid=4959500829331297171">http://www.json.org/json-zh.html</a> </p>     <p>除了上面的JSONArray、JSONObject可以将Java对象转换成JSON或是相反,将JSON字符串转换成Java对象,还有一个对象也可以完成上面的功能,它就是JSONSerializer;下面我们就来看看它们是怎么玩转Java对象和JSON的。 </p>     <p><b>二、 </b><b>Java</b><b>对象序列化成</b><b>JSON</b><b>对象</b> </p>     <p>1、 将JavaObject转换吃JSON字符串 </p>     <p>在JsonlibTest中添加如下代码: </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/*=========================Java Object >>>> JSON String ===========================*/</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b>转Java Bean对象到JSON</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate Nov 28, 2010 2:35:54 PM</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> writeEntity2JSON() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java Bean >>> JSON Object=================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONObject.fromObject(bean).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java Bean >>> JSON Array=================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONArray.fromObject(bean).toString());<span style="color:#008000;">//array会在最外层套上[]</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java Bean >>> JSON Object =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONSerializer.toJSON(bean).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"========================JsonConfig========================"</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    JsonConfig jsonConfig = <span style="color:#0000ff;">new</span> JsonConfig();   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    jsonConfig.registerJsonValueProcessor(Birthday.<span style="color:#0000ff;">class</span>, <span style="color:#0000ff;">new</span> JsonValueProcessor() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">public</span> Object processArrayValue(Object value, JsonConfig jsonConfig) {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#0000ff;">if</span> (value == null) {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">                <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">new</span> Date();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#0000ff;">return</span> value;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">public</span> Object processObjectValue(String key, Object value, JsonConfig jsonConfig) {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            fail(<span style="color:#006080;">"key:"</span> + key);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#0000ff;">return</span> value + <span style="color:#006080;">"##修改过的日期"</span>;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    });</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    jsonObject = JSONObject.fromObject(bean, jsonConfig);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(jsonObject.toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    Student student = (Student) JSONObject.toBean(jsonObject, Student.<span style="color:#0000ff;">class</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(jsonObject.getString(<span style="color:#006080;">"birthday"</span>));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(student.toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"#####################JsonPropertyFilter############################"</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    jsonConfig.setJsonPropertyFilter(<span style="color:#0000ff;">new</span> PropertyFilter() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">boolean</span> apply(Object source, String name, Object value) {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            fail(source + <span style="color:#006080;">"%%%"</span> + name + <span style="color:#006080;">"--"</span> + value);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#008000;">//忽略birthday属性</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#0000ff;">if</span> (value != null && Birthday.<span style="color:#0000ff;">class</span>.isAssignableFrom(value.getClass())) {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">                <span style="color:#0000ff;">return</span> true;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#0000ff;">return</span> false;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    });  </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONObject.fromObject(bean, jsonConfig).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"#################JavaPropertyFilter##################"</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    jsonConfig.setRootClass(Student.<span style="color:#0000ff;">class</span>);   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    jsonConfig.setJavaPropertyFilter(<span style="color:#0000ff;">new</span> PropertyFilter() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">boolean</span> apply(Object source, String name, Object value) {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            fail(name + <span style="color:#006080;">"@"</span> + value + <span style="color:#006080;">"#"</span> + source);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#0000ff;">if</span> (<span style="color:#006080;">"id"</span>.equals(name) || <span style="color:#006080;">"email"</span>.equals(name)) {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">                value = name + <span style="color:#006080;">"@@"</span>;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">                <span style="color:#0000ff;">return</span> true;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#0000ff;">return</span> false;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    });   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//jsonObject = JSONObject.fromObject(bean, jsonConfig);</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//student = (Student) JSONObject.toBean(jsonObject, Student.class);</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//fail(student.toString());</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    student = (Student) JSONObject.toBean(jsonObject, jsonConfig);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"Student:"</span> + student.toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>      </div>     </div>     <p>fromObject将Java对象转换成json字符串,toBean将json对象转换成Java对象; </p>     <p>上面方法值得注意的是使用了JsonConfig这个对象,这个对象可以在序列化的时候对JavaObject的数据进行处理、过滤等 </p>     <p>上面的jsonConfig的registerJsonValueProcessor方法可以完成对象值的处理和修改,比如处理生日为null时,给一个特定的值。同样setJsonPropertyFilter和setJavaPropertyFilter都是完成对转换后的值的处理。 </p>     <p>运行上面的代码可以在控制台看到如下结果: </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java Bean >>> JSON Object==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">{<span style="color:#006080;">"address"</span>:<span style="color:#006080;">"address"</span>,<span style="color:#006080;">"birthday"</span>:{<span style="color:#006080;">"birthday"</span>:<span style="color:#006080;">"2010-11-22"</span>},<span style="color:#006080;">"email"</span>:<span style="color:#006080;">"email"</span>,<span style="color:#006080;">"id"</span>:1,<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"haha"</span>}</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java Bean >>> JSON Array==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">[{<span style="color:#006080;">"address"</span>:<span style="color:#006080;">"address"</span>,<span style="color:#006080;">"birthday"</span>:{<span style="color:#006080;">"birthday"</span>:<span style="color:#006080;">"2010-11-22"</span>},<span style="color:#006080;">"email"</span>:<span style="color:#006080;">"email"</span>,<span style="color:#006080;">"id"</span>:1,<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"haha"</span>}]</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java Bean >>> JSON Object ==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">{<span style="color:#006080;">"address"</span>:<span style="color:#006080;">"address"</span>,<span style="color:#006080;">"birthday"</span>:{<span style="color:#006080;">"birthday"</span>:<span style="color:#006080;">"2010-11-22"</span>},<span style="color:#006080;">"email"</span>:<span style="color:#006080;">"email"</span>,<span style="color:#006080;">"id"</span>:1,<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"haha"</span>}</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">========================JsonConfig========================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">key:birthday</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">{<span style="color:#006080;">"address"</span>:<span style="color:#006080;">"address"</span>,<span style="color:#006080;">"birthday"</span>:<span style="color:#006080;">"2010-11-22##修改过的日期"</span>,<span style="color:#006080;">"email"</span>:<span style="color:#006080;">"email"</span>,<span style="color:#006080;">"id"</span>:1,<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"haha"</span>}</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">2010-11-22##修改过的日期</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">haha#1#address#null#email</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">#####################JsonPropertyFilter############################</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">haha#1#address#2010-11-22#email%%%address--address</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">haha#1#address#2010-11-22#email%%%birthday--2010-11-22</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">haha#1#address#2010-11-22#email%%%email--email</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">haha#1#address#2010-11-22#email%%%id--1</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">haha#1#address#2010-11-22#email%%%name--haha</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">{<span style="color:#006080;">"address"</span>:<span style="color:#006080;">"address"</span>,<span style="color:#006080;">"email"</span>:<span style="color:#006080;">"email"</span>,<span style="color:#006080;">"id"</span>:1,<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"haha"</span>}</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">#################JavaPropertyFilter##################</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">address@address#null#0#null#null#null</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">birthday@2010-11-22##修改过的日期#null#0#address#null#null</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">email@email#null#0#address#null#null</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">id@1#null#0#address#null#null</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">name@haha#null#0#address#null#null</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">Student:haha#0#address#null#null</pre>      </div>     </div>     <p>2、 将JavaList集合转换吃JSON字符串 </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b>转换Java List集合到JSON</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate Nov 28, 2010 2:36:15 PM</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> writeList2JSON() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java List >>> JSON Array=================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    List<Student> stu = <span style="color:#0000ff;">new</span> ArrayList<Student>();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    stu.add(bean);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bean.setName(<span style="color:#006080;">"jack"</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    stu.add(bean);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONArray.fromObject(stu).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONSerializer.toJSON(stu).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>      </div>     </div>     <p>运行此方法后,可以看到控制台输出: </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java List >>> JSON Array==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">[{<span style="color:#006080;">"address"</span>:<span style="color:#006080;">"address"</span>,<span style="color:#006080;">"birthday"</span>:{<span style="color:#006080;">"birthday"</span>:<span style="color:#006080;">"2010-11-22"</span>},<span style="color:#006080;">"email"</span>:<span style="color:#006080;">"email"</span>,<span style="color:#006080;">"id"</span>:1,<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"jack"</span>},</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">{<span style="color:#006080;">"address"</span>:<span style="color:#006080;">"address"</span>,<span style="color:#006080;">"birthday"</span>:{<span style="color:#006080;">"birthday"</span>:<span style="color:#006080;">"2010-11-22"</span>},<span style="color:#006080;">"email"</span>:<span style="color:#006080;">"email"</span>,<span style="color:#006080;">"id"</span>:1,<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"jack"</span>}]</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">[{<span style="color:#006080;">"address"</span>:<span style="color:#006080;">"address"</span>,<span style="color:#006080;">"birthday"</span>:{<span style="color:#006080;">"birthday"</span>:<span style="color:#006080;">"2010-11-22"</span>},<span style="color:#006080;">"email"</span>:<span style="color:#006080;">"email"</span>,<span style="color:#006080;">"id"</span>:1,<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"jack"</span>},</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">{<span style="color:#006080;">"address"</span>:<span style="color:#006080;">"address"</span>,<span style="color:#006080;">"birthday"</span>:{<span style="color:#006080;">"birthday"</span>:<span style="color:#006080;">"2010-11-22"</span>},<span style="color:#006080;">"email"</span>:<span style="color:#006080;">"email"</span>,<span style="color:#006080;">"id"</span>:1,<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"jack"</span>}]</pre>      </div>     </div>     <p>如果你是转换List集合,一定得用JSONArray或是JSONSrializer提供的序列化方法。如果你用 JSONObject.fromObject方法转换List会出现异常,通常使用JSONSrializer这个JSON序列化的方法,它会自动识别你传递的对象的类型,然后转换成相应的JSON字符串。 </p>     <p>3、 将Map集合转换成JSON对象 </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b>转Java Map对象到JSON</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate Nov 28, 2010 2:37:35 PM</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> writeMap2JSON() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    Map<String, Object> map = <span style="color:#0000ff;">new</span> HashMap<String, Object>();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    map.put(<span style="color:#006080;">"A"</span>, bean);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bean.setName(<span style="color:#006080;">"jack"</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    map.put(<span style="color:#006080;">"B"</span>, bean);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    map.put(<span style="color:#006080;">"name"</span>, <span style="color:#006080;">"json"</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    map.put(<span style="color:#006080;">"bool"</span>, Boolean.TRUE);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    map.put(<span style="color:#006080;">"int"</span>, <span style="color:#0000ff;">new</span> Integer(1));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    map.put(<span style="color:#006080;">"arr"</span>, <span style="color:#0000ff;">new</span> String[] { <span style="color:#006080;">"a"</span>, <span style="color:#006080;">"b"</span> });</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    map.put(<span style="color:#006080;">"func"</span>, <span style="color:#006080;">"function(i){ return this.arr[i]; }"</span>); </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java Map >>> JSON Object=================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONObject.fromObject(map).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java Map >>> JSON Array =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONArray.fromObject(map).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java Map >>> JSON Object=================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONSerializer.toJSON(map).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>      </div>     </div>     <p>上面的Map集合有JavaBean、String、Boolean、Integer、以及Array和js的function函数的字符串。 </p>     <p>运行上面的程序,结果如下: </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java Map >>> JSON Object==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">{<span style="color:#006080;">"arr"</span>:[<span style="color:#006080;">"a"</span>,<span style="color:#006080;">"b"</span>],<span style="color:#006080;">"A"</span>:{<span style="color:#006080;">"address"</span>:<span style="color:#006080;">"address"</span>,<span style="color:#006080;">"birthday"</span>:{<span style="color:#006080;">"birthday"</span>:<span style="color:#006080;">"2010-11-22"</span>},<span style="color:#006080;">"email"</span>:<span style="color:#006080;">"email"</span>,<span style="color:#006080;">"id"</span>:1,<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"jack"</span>},<span style="color:#006080;">"int"</span>:1,</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;">"B"</span>:{<span style="color:#006080;">"address"</span>:<span style="color:#006080;">"address"</span>,<span style="color:#006080;">"birthday"</span>:{<span style="color:#006080;">"birthday"</span>:<span style="color:#006080;">"2010-11-22"</span>},<span style="color:#006080;">"email"</span>:<span style="color:#006080;">"email"</span>,<span style="color:#006080;">"id"</span>:1,<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"jack"</span>},<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"json"</span>,</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;">"func"</span>:function(i){ <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">this</span>.arr[i]; },<span style="color:#006080;">"bool"</span>:true}</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java Map >>> JSON Array ==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">[{<span style="color:#006080;">"arr"</span>:[<span style="color:#006080;">"a"</span>,<span style="color:#006080;">"b"</span>],<span style="color:#006080;">"A"</span>:{<span style="color:#006080;">"address"</span>:<span style="color:#006080;">"address"</span>,<span style="color:#006080;">"birthday"</span>:{<span style="color:#006080;">"birthday"</span>:<span style="color:#006080;">"2010-11-22"</span>},<span style="color:#006080;">"email"</span>:<span style="color:#006080;">"email"</span>,<span style="color:#006080;">"id"</span>:1,<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"jack"</span>},<span style="color:#006080;">"int"</span>:1,</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;">"B"</span>:{<span style="color:#006080;">"address"</span>:<span style="color:#006080;">"address"</span>,<span style="color:#006080;">"birthday"</span>:{<span style="color:#006080;">"birthday"</span>:<span style="color:#006080;">"2010-11-22"</span>},<span style="color:#006080;">"email"</span>:<span style="color:#006080;">"email"</span>,<span style="color:#006080;">"id"</span>:1,<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"jack"</span>},<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"json"</span>,</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;">"func"</span>:function(i){ <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">this</span>.arr[i]; },<span style="color:#006080;">"bool"</span>:true}]</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java Map >>> JSON Object==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">{<span style="color:#006080;">"arr"</span>:[<span style="color:#006080;">"a"</span>,<span style="color:#006080;">"b"</span>],<span style="color:#006080;">"A"</span>:{<span style="color:#006080;">"address"</span>:<span style="color:#006080;">"address"</span>,<span style="color:#006080;">"birthday"</span>:{<span style="color:#006080;">"birthday"</span>:<span style="color:#006080;">"2010-11-22"</span>},<span style="color:#006080;">"email"</span>:<span style="color:#006080;">"email"</span>,<span style="color:#006080;">"id"</span>:1,<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"jack"</span>},<span style="color:#006080;">"int"</span>:1,</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;">"B"</span>:{<span style="color:#006080;">"address"</span>:<span style="color:#006080;">"address"</span>,<span style="color:#006080;">"birthday"</span>:{<span style="color:#006080;">"birthday"</span>:<span style="color:#006080;">"2010-11-22"</span>},<span style="color:#006080;">"email"</span>:<span style="color:#006080;">"email"</span>,<span style="color:#006080;">"id"</span>:1,<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"jack"</span>},<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"json"</span>,</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;">"func"</span>:function(i){ <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">this</span>.arr[i]; },<span style="color:#006080;">"bool"</span>:true}</pre>      </div>     </div>     <p>4、 将更多类型转换成JSON </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b>  转换更多数组类型到JSON</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate Nov 28, 2010 2:39:19 PM</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> writeObject2JSON() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    String[] sa = {<span style="color:#006080;">"a"</span>, <span style="color:#006080;">"b"</span>, <span style="color:#006080;">"c"</span>};</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java StringArray >>> JSON Array =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONArray.fromObject(sa).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONSerializer.toJSON(sa).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java boolean Array >>> JSON Array =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">boolean</span>[] bo = { true, false, true };</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONArray.fromObject(bo).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONSerializer.toJSON(bo).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    Object[] o = { 1, <span style="color:#006080;">"a"</span>, true, <span style="color:#006080;">'A'</span>, sa, bo };</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java Object Array >>> JSON Array =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONArray.fromObject(o).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONSerializer.toJSON(o).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java String >>> JSON =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONArray.fromObject(<span style="color:#006080;">"['json','is','easy']"</span>).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONObject.fromObject(<span style="color:#006080;">"{'json':'is easy'}"</span>).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONSerializer.toJSON(<span style="color:#006080;">"['json','is','easy']"</span>).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java JSONObject >>> JSON =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    jsonObject = <span style="color:#0000ff;">new</span> JSONObject()   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        .element(<span style="color:#006080;">"string"</span>, <span style="color:#006080;">"JSON"</span>)</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        .element(<span style="color:#006080;">"integer"</span>, <span style="color:#006080;">"1"</span>)</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        .element(<span style="color:#006080;">"double"</span>, <span style="color:#006080;">"2.0"</span>)</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        .element(<span style="color:#006080;">"boolean"</span>, <span style="color:#006080;">"true"</span>);  </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONSerializer.toJSON(jsonObject).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java JSONArray >>> JSON =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    jsonArray = <span style="color:#0000ff;">new</span> JSONArray()   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        .element( <span style="color:#006080;">"JSON"</span> )   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        .element( <span style="color:#006080;">"1"</span> )   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        .element( <span style="color:#006080;">"2.0"</span> )   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        .element( <span style="color:#006080;">"true"</span> ); </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(JSONSerializer.toJSON(jsonArray).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java JSONArray JsonConfig#setArrayMode >>> JSON =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    List input = <span style="color:#0000ff;">new</span> ArrayList();   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    input.add(<span style="color:#006080;">"JSON"</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    input.add(<span style="color:#006080;">"1"</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    input.add(<span style="color:#006080;">"2.0"</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    input.add(<span style="color:#006080;">"true"</span>);   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON( input );   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    JsonConfig jsonConfig = <span style="color:#0000ff;">new</span> JsonConfig();   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    jsonConfig.setArrayMode( JsonConfig.MODE_OBJECT_ARRAY );   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    Object[] output = (Object[]) JSONSerializer.toJava(jsonArray, jsonConfig);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    System.out.println(output[0]);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java JSONFunction >>> JSON =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    String str = <span style="color:#006080;">"{'func': function( param ){ doSomethingWithParam(param); }}"</span>;   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    JSONObject jsonObject = (JSONObject) JSONSerializer.toJSON(str);   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    JSONFunction func = (JSONFunction) jsonObject.get(<span style="color:#006080;">"func"</span>);   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(func.getParams()[0]);   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(func.getText() );   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>      </div>     </div>     <p>运行后结果如下: </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java StringArray >>> JSON Array ==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">[<span style="color:#006080;">"a"</span>,<span style="color:#006080;">"b"</span>,<span style="color:#006080;">"c"</span>]</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">[<span style="color:#006080;">"a"</span>,<span style="color:#006080;">"b"</span>,<span style="color:#006080;">"c"</span>]</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java <span style="color:#0000ff;">boolean</span> Array >>> JSON Array ==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">[true,false,true]</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">[true,false,true]</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java Object Array >>> JSON Array ==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">[1,<span style="color:#006080;">"a"</span>,true,<span style="color:#006080;">"A"</span>,[<span style="color:#006080;">"a"</span>,<span style="color:#006080;">"b"</span>,<span style="color:#006080;">"c"</span>],[true,false,true]]</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">[1,<span style="color:#006080;">"a"</span>,true,<span style="color:#006080;">"A"</span>,[<span style="color:#006080;">"a"</span>,<span style="color:#006080;">"b"</span>,<span style="color:#006080;">"c"</span>],[true,false,true]]</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java String >>> JSON ==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">[<span style="color:#006080;">"json"</span>,<span style="color:#006080;">"is"</span>,<span style="color:#006080;">"easy"</span>]</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">{<span style="color:#006080;">"json"</span>:<span style="color:#006080;">"is easy"</span>}</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">[<span style="color:#006080;">"json"</span>,<span style="color:#006080;">"is"</span>,<span style="color:#006080;">"easy"</span>]</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java JSONObject >>> JSON ==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">{<span style="color:#006080;">"string"</span>:<span style="color:#006080;">"JSON"</span>,<span style="color:#006080;">"integer"</span>:<span style="color:#006080;">"1"</span>,<span style="color:#006080;">"double"</span>:<span style="color:#006080;">"2.0"</span>,<span style="color:#006080;">"boolean"</span>:<span style="color:#006080;">"true"</span>}</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java JSONArray >>> JSON ==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">[<span style="color:#006080;">"JSON"</span>,<span style="color:#006080;">"1"</span>,<span style="color:#006080;">"2.0"</span>,<span style="color:#006080;">"true"</span>]</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java JSONArray JsonConfig#setArrayMode >>> JSON ==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">JSON</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java JSONFunction >>> JSON ==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">param</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">doSomethingWithParam(param);</pre>      </div>     </div>     <p>这里还有一个JSONFunction的对象,可以转换JavaScript的function。可以获取方法参数和方法体。同时,还可以用JSONObject、JSONArray构建Java对象,完成Java对象到JSON字符串的转换。 </p>     <p><b>三、 </b><b>JSON</b><b>对象反序列化成</b><b>Java</b><b>对象</b> </p>     <p>1、 将json字符串转成Java对象 </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">private</span> String json = <span style="color:#006080;">"{\"address\":\"chian\",\"birthday\":{\"birthday\":\"2010-11-22\"},"</span> +</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;">"\"email\":\"email@123.com\",\"id\":22,\"name\":\"tom\"}"</span>;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b>将json字符串转化为java对象</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate Nov 28, 2010 3:01:16 PM</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> readJSON2Bean() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============JSON Object String >>> Java Bean =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    jsonObject = JSONObject.fromObject(json);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    Student stu = (Student) JSONObject.toBean(jsonObject, Student.<span style="color:#0000ff;">class</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(stu.toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>      </div>     </div>     <p>运行后,结果如下: </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre>==============JSON Object String >>> Java Bean ==================</pre>       <pre>tom#22#chian#2010-11-22#email@123.com</pre>      </div>     </div>     <p>2、 将json字符串转换成动态Java对象(MorphDynaBean) </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">private</span> String json = <span style="color:#006080;">"{\"address\":\"chian\",\"birthday\":{\"birthday\":\"2010-11-22\"},"</span>+</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;">"\"email\":\"email@123.com\",\"id\":22,\"name\":\"tom\"}"</span>;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> readJSON2DynaBean() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">try</span> {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(<span style="color:#006080;">"==============JSON Object String >>> Java MorphDynaBean =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        JSON jo = JSONSerializer.toJSON(json);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Object o = JSONSerializer.toJava(jo);<span style="color:#008000;">//MorphDynaBean</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(PropertyUtils.getProperty(o, <span style="color:#006080;">"address"</span>).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        jsonObject = JSONObject.fromObject(json);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(jsonObject.getString(<span style="color:#006080;">"email"</span>));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        o = JSONSerializer.toJava(jsonObject);<span style="color:#008000;">//MorphDynaBean</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(PropertyUtils.getProperty(o, <span style="color:#006080;">"name"</span>).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    } <span style="color:#0000ff;">catch</span> (IllegalAccessException e) {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        e.printStackTrace();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    } <span style="color:#0000ff;">catch</span> (InvocationTargetException e) {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        e.printStackTrace();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    } <span style="color:#0000ff;">catch</span> (NoSuchMethodException e) {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        e.printStackTrace();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>      </div>     </div>     <p>转换后的对象Object是一个MorphDynaBean的动态JavaBean,通过PropertyUtils可以获得指定的属性的值。 </p>     <p>运行后结果如下: </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre>==============JSON Object String >>> Java MorphDynaBean =============</pre>       <pre>chian</pre>       <pre>email@123.com</pre>       <pre>tom</pre>      </div>     </div>     <p>3、 将json字符串转成Java的Array数组 </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">private</span> String json = <span style="color:#006080;">"{\"address\":\"chian\",\"birthday\":{\"birthday\":\"2010-11-22\"},"</span>+</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;">"\"email\":\"email@123.com\",\"id\":22,\"name\":\"tom\"}"</span>;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> readJSON2Array() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">try</span> {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(<span style="color:#006080;">"==============JSON Arry String >>> Java Array =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        json = <span style="color:#006080;">"["</span> + json + <span style="color:#006080;">"]"</span>;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        jsonArray = JSONArray.fromObject(json);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(<span style="color:#006080;">"#%%%"</span> + jsonArray.get(0).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Object[] os = jsonArray.toArray();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.out.println(os.length);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(JSONArray.fromObject(json).join(<span style="color:#006080;">""</span>));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(os[0].toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Student[] stus = (Student[]) JSONArray.toArray(jsonArray, Student.<span style="color:#0000ff;">class</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.out.println(stus.length);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.out.println(stus[0]);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    } <span style="color:#0000ff;">catch</span> (Exception e) {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        e.printStackTrace();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>      </div>     </div>     <p>运行的结果如下: </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre>==============JSON Arry String >>> Java Array ==================</pre>       <pre>#%%%{<span style="color:#006080;">"address"</span>:<span style="color:#006080;">"chian"</span>,<span style="color:#006080;">"birthday"</span>:{<span style="color:#006080;">"birthday"</span>:<span style="color:#006080;">"2010-11-22"</span>},<span style="color:#006080;">"email"</span>:<span style="color:#006080;">"email@123.com"</span>,<span style="color:#006080;">"id"</span>:22,<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"tom"</span>}</pre>       <pre>1</pre>       <pre>{<span style="color:#006080;">"address"</span>:<span style="color:#006080;">"chian"</span>,<span style="color:#006080;">"birthday"</span>:{<span style="color:#006080;">"birthday"</span>:<span style="color:#006080;">"2010-11-22"</span>},<span style="color:#006080;">"email"</span>:<span style="color:#006080;">"email@123.com"</span>,<span style="color:#006080;">"id"</span>:22,<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"tom"</span>}</pre>       <pre>{<span style="color:#006080;">"address"</span>:<span style="color:#006080;">"chian"</span>,<span style="color:#006080;">"birthday"</span>:{<span style="color:#006080;">"birthday"</span>:<span style="color:#006080;">"2010-11-22"</span>},<span style="color:#006080;">"email"</span>:<span style="color:#006080;">"email@123.com"</span>,<span style="color:#006080;">"id"</span>:22,<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"tom"</span>}</pre>       <pre>1</pre>       <pre>tom#22#chian#2010-11-22#email@123.com</pre>      </div>     </div>     <p>4、 将JSON字符串转成Java的List集合 </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">private</span> String json = <span style="color:#006080;">"{\"address\":\"chian\",\"birthday\":{\"birthday\":\"2010-11-22\"},"</span>+</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;">"\"email\":\"email@123.com\",\"id\":22,\"name\":\"tom\"}"</span>;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> readJSON2List() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">try</span> {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(<span style="color:#006080;">"==============JSON Arry String >>> Java List =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        json = <span style="color:#006080;">"["</span> + json + <span style="color:#006080;">"]"</span>;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        jsonArray = JSONArray.fromObject(json);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        List<Student> list = JSONArray.toList(jsonArray, Student.<span style="color:#0000ff;">class</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.out.println(list.size());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.out.println(list.get(0));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        list = JSONArray.toList(jsonArray);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.out.println(list.size());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.out.println(list.get(0));<span style="color:#008000;">//MorphDynaBean</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    } <span style="color:#0000ff;">catch</span> (Exception e) {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        e.printStackTrace();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>      </div>     </div>     <p>运行后结果如下: </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre>==============JSON Arry String >>> Java List ==================</pre>       <pre>1</pre>       <pre>tom#22#chian#2010-11-22#email@123.com</pre>       <pre>1</pre>       <pre>net.sf.ezmorph.bean.MorphDynaBean@141b571[</pre>       <pre>  {id=22, birthday=net.sf.ezmorph.bean.MorphDynaBean@b23210[</pre>       <pre>  {birthday=2010-11-22}</pre>       <pre>], address=chian, email=email@123.com, name=tom}</pre>       <pre>]</pre>      </div>     </div>     <p>5、 将json字符串转换成Collection接口 </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">private</span> String json = <span style="color:#006080;">"{\"address\":\"chian\",\"birthday\":{\"birthday\":\"2010-11-22\"},"</span>+</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;">"\"email\":\"email@123.com\",\"id\":22,\"name\":\"tom\"}"</span>;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> readJSON2Collection() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">try</span> {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(<span style="color:#006080;">"==============JSON Arry String >>> Java Collection =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        json = <span style="color:#006080;">"["</span> + json + <span style="color:#006080;">"]"</span>;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        jsonArray = JSONArray.fromObject(json);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Collection<Student> con = JSONArray.toCollection(jsonArray, Student.<span style="color:#0000ff;">class</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.out.println(con.size());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Object[] stt = con.toArray();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.out.println(stt.length);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(stt[0].toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    } <span style="color:#0000ff;">catch</span> (Exception e) {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        e.printStackTrace();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>      </div>     </div>     <p>刚才上面的将json转换成list提示该方法过时,这里有toCollection,可以用此方法代替toList方法;运行后结果如下: </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre>==============JSON Arry String >>> Java Collection ==================</pre>       <pre>1</pre>       <pre>1</pre>       <pre>tom#22#chian#2010-11-22#email@123.com</pre>      </div>     </div>     <p>6、 将json字符串转换成Map集合 </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> readJSON2Map() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">try</span> {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(<span style="color:#006080;">"==============JSON Arry String >>> Java Map =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        json = <span style="color:#006080;">"{\"arr\":[\"a\",\"b\"],\"A\":{\"address\":\"address\",\"birthday\":{\"birthday\":\"2010-11-22\"},"</span>+</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;">"\"email\":\"email\",\"id\":1,\"name\":\"jack\"},\"int\":1,"</span>+</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;">"\"B\":{\"address\":\"address\",\"birthday\":{\"birthday\":\"2010-11-22\"},"</span>+</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;">"\"email\":\"email\",\"id\":1,\"name\":\"jack\"},\"name\":\"json\",\"bool\":true}"</span>;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        jsonObject = JSONObject.fromObject(json);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Map<String, Class<?>> clazzMap = <span style="color:#0000ff;">new</span> HashMap<String, Class<?>>();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        clazzMap.put(<span style="color:#006080;">"arr"</span>, String[].<span style="color:#0000ff;">class</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        clazzMap.put(<span style="color:#006080;">"A"</span>, Student.<span style="color:#0000ff;">class</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        clazzMap.put(<span style="color:#006080;">"B"</span>, Student.<span style="color:#0000ff;">class</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Map<String, ?> mapBean = (Map) JSONObject.toBean(jsonObject, Map.<span style="color:#0000ff;">class</span>, clazzMap);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.out.println(mapBean);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Set<String> set = mapBean.keySet();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Iterator<String> iter = set.iterator();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">while</span> (iter.hasNext()) {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            String key = iter.next();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            fail(key + <span style="color:#006080;">":"</span> + mapBean.get(key).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    } <span style="color:#0000ff;">catch</span> (Exception e) {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        e.printStackTrace();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>      </div>     </div>     <p>运行后结果如下: </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre>==============JSON Arry String >>> Java Map ==================</pre>       <pre>{A=jack#1#address#2010-11-22#email, arr=[a, b], B=jack#1#address#2010-11-22#email, <span style="color:#0000ff;">int</span>=1, name=json, bool=true}</pre>       <pre>A:jack#1#address#2010-11-22#email</pre>       <pre>arr:[a, b]</pre>       <pre>B:jack#1#address#2010-11-22#email</pre>       <pre><span style="color:#0000ff;">int</span>:1</pre>       <pre>name:json</pre>       <pre>bool:true</pre>      </div>     </div>     <p><b>四、 </b><b>JSON-lib</b><b>对</b><b>XML</b><b>的支持</b> </p>     <p>1、 将Java对象到XML </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/*============================Java Object >>>>> XML ==========================*/</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b> 转换Java对象到XML</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * 需要额外的jar包:xom.jar</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate Nov 28, 2010 2:39:55 PM</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> writeObject2XML() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    XMLSerializer xmlSerializer = <span style="color:#0000ff;">new</span> XMLSerializer();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java String Array >>> XML =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//xmlSerializer.setElementName("bean");</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(xmlSerializer.write(JSONArray.fromObject(bean)));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    String[] sa = {<span style="color:#006080;">"a"</span>, <span style="color:#006080;">"b"</span>, <span style="color:#006080;">"c"</span>};</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java String Array >>> XML =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(xmlSerializer.write(JSONArray.fromObject(sa)));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java boolean Array >>> XML =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">boolean</span>[] bo = { true, false, true };</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(xmlSerializer.write(JSONArray.fromObject(bo)));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(xmlSerializer.write(JSONSerializer.toJSON(bo)));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    Object[] o = { 1, <span style="color:#006080;">"a"</span>, true, <span style="color:#006080;">'A'</span>, sa, bo };</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java Object Array >>> JSON Array =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(xmlSerializer.write(JSONArray.fromObject(o)));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(xmlSerializer.write(JSONSerializer.toJSON(o)));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java String >>> JSON =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(xmlSerializer.write(JSONArray.fromObject(<span style="color:#006080;">"['json','is','easy']"</span>)).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(xmlSerializer.write(JSONObject.fromObject(<span style="color:#006080;">"{'json':'is easy'}"</span>)).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(xmlSerializer.write(JSONSerializer.toJSON(<span style="color:#006080;">"['json','is','easy']"</span>)).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>      </div>     </div>     <p>主要运用的是XMLSerializer的write方法,这个方法可以完成java对象到xml的转换,不过你很容易就可以看到这个xml序列化对象,需要先将java对象转成json对象,然后再将json转换吃xml文档。 </p>     <p>运行后结果如下: </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java String Array <span style="color:#0000ff;">>>></span> XML ==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><?</span><span style="color:#800000;">xml</span> <span style="color:#ff0000;">version</span><span style="color:#0000ff;">="1.0"</span> <span style="color:#ff0000;">encoding</span><span style="color:#0000ff;">="UTF-8"</span>?<span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">a</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="object"</span><span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">address</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>address<span style="color:#0000ff;"></</span><span style="color:#800000;">address</span><span style="color:#0000ff;">><</span><span style="color:#800000;">birthday</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="object"</span><span style="color:#0000ff;">><</span><span style="color:#800000;">birthday</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>2010-11-22<span style="color:#0000ff;"></</span><span style="color:#800000;">birthday</span><span style="color:#0000ff;">></</span><span style="color:#800000;">birthday</span><span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">email</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>email<span style="color:#0000ff;"></</span><span style="color:#800000;">email</span><span style="color:#0000ff;">><</span><span style="color:#800000;">id</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="number"</span><span style="color:#0000ff;">></span>1<span style="color:#0000ff;"></</span><span style="color:#800000;">id</span><span style="color:#0000ff;">><</span><span style="color:#800000;">name</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>haha<span style="color:#0000ff;"></</span><span style="color:#800000;">name</span><span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">></</span><span style="color:#800000;">a</span><span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java String Array <span style="color:#0000ff;">>>></span> XML ==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><?</span><span style="color:#800000;">xml</span> <span style="color:#ff0000;">version</span><span style="color:#0000ff;">="1.0"</span> <span style="color:#ff0000;">encoding</span><span style="color:#0000ff;">="UTF-8"</span>?<span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">a</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>a<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>b<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>c<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">></</span><span style="color:#800000;">a</span><span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java boolean Array <span style="color:#0000ff;">>>></span> XML ==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><?</span><span style="color:#800000;">xml</span> <span style="color:#ff0000;">version</span><span style="color:#0000ff;">="1.0"</span> <span style="color:#ff0000;">encoding</span><span style="color:#0000ff;">="UTF-8"</span>?<span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">a</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="boolean"</span><span style="color:#0000ff;">></span>true<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="boolean"</span><span style="color:#0000ff;">></span>false<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="boolean"</span><span style="color:#0000ff;">></span>true<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">></</span><span style="color:#800000;">a</span><span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><?</span><span style="color:#800000;">xml</span> <span style="color:#ff0000;">version</span><span style="color:#0000ff;">="1.0"</span> <span style="color:#ff0000;">encoding</span><span style="color:#0000ff;">="UTF-8"</span>?<span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">a</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="boolean"</span><span style="color:#0000ff;">></span>true<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="boolean"</span><span style="color:#0000ff;">></span>false<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="boolean"</span><span style="color:#0000ff;">></span>true<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">></</span><span style="color:#800000;">a</span><span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java Object Array <span style="color:#0000ff;">>>></span> JSON Array ==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><?</span><span style="color:#800000;">xml</span> <span style="color:#ff0000;">version</span><span style="color:#0000ff;">="1.0"</span> <span style="color:#ff0000;">encoding</span><span style="color:#0000ff;">="UTF-8"</span>?<span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">a</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="number"</span><span style="color:#0000ff;">></span>1<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>a<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="boolean"</span><span style="color:#0000ff;">></span>true<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>A<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="array"</span><span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>a<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>b<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>c<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="array"</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="boolean"</span><span style="color:#0000ff;">></span>true<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="boolean"</span><span style="color:#0000ff;">></span>false<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="boolean"</span><span style="color:#0000ff;">></span>true<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">></</span><span style="color:#800000;">a</span><span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><?</span><span style="color:#800000;">xml</span> <span style="color:#ff0000;">version</span><span style="color:#0000ff;">="1.0"</span> <span style="color:#ff0000;">encoding</span><span style="color:#0000ff;">="UTF-8"</span>?<span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">a</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="number"</span><span style="color:#0000ff;">></span>1<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>a<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="boolean"</span><span style="color:#0000ff;">></span>true<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>A<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="array"</span><span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>a<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>b<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>c<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="array"</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="boolean"</span><span style="color:#0000ff;">></span>true<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="boolean"</span><span style="color:#0000ff;">></span>false<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="boolean"</span><span style="color:#0000ff;">></span>true<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">></</span><span style="color:#800000;">a</span><span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java String <span style="color:#0000ff;">>>></span> JSON ==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><?</span><span style="color:#800000;">xml</span> <span style="color:#ff0000;">version</span><span style="color:#0000ff;">="1.0"</span> <span style="color:#ff0000;">encoding</span><span style="color:#0000ff;">="UTF-8"</span>?<span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">a</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>json<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>is<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>easy<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">></</span><span style="color:#800000;">a</span><span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><?</span><span style="color:#800000;">xml</span> <span style="color:#ff0000;">version</span><span style="color:#0000ff;">="1.0"</span> <span style="color:#ff0000;">encoding</span><span style="color:#0000ff;">="UTF-8"</span>?<span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">o</span><span style="color:#0000ff;">><</span><span style="color:#800000;">json</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>is easy<span style="color:#0000ff;"></</span><span style="color:#800000;">json</span><span style="color:#0000ff;">></</span><span style="color:#800000;">o</span><span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><?</span><span style="color:#800000;">xml</span> <span style="color:#ff0000;">version</span><span style="color:#0000ff;">="1.0"</span> <span style="color:#ff0000;">encoding</span><span style="color:#0000ff;">="UTF-8"</span>?<span style="color:#0000ff;">></span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">a</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>json<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>is<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">><</span><span style="color:#800000;">e</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span><span style="color:#0000ff;">></span>easy<span style="color:#0000ff;"></</span><span style="color:#800000;">e</span><span style="color:#0000ff;">></</span><span style="color:#800000;">a</span><span style="color:#0000ff;">></span></pre>      </div>     </div>     <p>上面的节点名称有点乱,你可以通过setElementName设置节点名称 </p>     <p>2、 将XML转换成Java对象 </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/*============================XML String >>>>> Java Object ==========================*/</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b>转换xml文档到java对象</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate Nov 28, 2010 3:00:27 PM</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> readXML2Object() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    XMLSerializer xmlSerializer = <span style="color:#0000ff;">new</span> XMLSerializer();</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"============== XML >>>> Java String Array =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    String[] sa = {<span style="color:#006080;">"a"</span>, <span style="color:#006080;">"b"</span>, <span style="color:#006080;">"c"</span>};</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    jsonArray = (JSONArray) xmlSerializer.read(xmlSerializer.write(JSONArray.fromObject(sa)));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(jsonArray.toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    String[] s = (String[]) JSONArray.toArray(jsonArray, String.<span style="color:#0000ff;">class</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(s[0].toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"============== XML >>>> Java boolean Array =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">boolean</span>[] bo = { true, false, true };</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    jsonArray = (JSONArray) xmlSerializer.read(xmlSerializer.write(JSONArray.fromObject(bo)));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bo = (<span style="color:#0000ff;">boolean</span>[]) JSONArray.toArray(jsonArray, <span style="color:#0000ff;">boolean</span>.<span style="color:#0000ff;">class</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(bo.toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    System.out.println(bo[0]);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    jsonArray = (JSONArray) xmlSerializer.read(xmlSerializer.write(JSONSerializer.toJSON(bo)));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bo = (<span style="color:#0000ff;">boolean</span>[]) JSONArray.toArray(jsonArray, <span style="color:#0000ff;">boolean</span>.<span style="color:#0000ff;">class</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(bo.toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    System.out.println(bo[0]);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java Object Array >>> JSON Array =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    Object[] o = { 1, <span style="color:#006080;">"a"</span>, true, <span style="color:#006080;">'A'</span>, sa, bo };</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    jsonArray = (JSONArray) xmlSerializer.read(xmlSerializer.write(JSONArray.fromObject(o)));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    System.out.println(jsonArray.getInt(0));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    System.out.println(jsonArray.get(1));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    System.out.println(jsonArray.getBoolean(2));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    jsonArray = (JSONArray) xmlSerializer.read(xmlSerializer.write(JSONSerializer.toJSON(o)));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    System.out.println(jsonArray.get(4));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    System.out.println(jsonArray.getJSONArray(5).get(0));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    System.out.println(jsonArray.get(5));</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(<span style="color:#006080;">"==============Java String >>> JSON =================="</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    jsonArray = (JSONArray) xmlSerializer.read(xmlSerializer.write(JSONArray.fromObject(<span style="color:#006080;">"['json','is','easy']"</span>)).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    s = (String[]) JSONArray.toArray(jsonArray, String.<span style="color:#0000ff;">class</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(s[0].toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    jsonObject = (JSONObject) xmlSerializer.read(xmlSerializer.write(JSONObject.fromObject(<span style="color:#006080;">"{'json':'is easy'}"</span>)).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    Object obj = JSONObject.toBean(jsonObject);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    System.out.println(obj);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    jsonArray = (JSONArray) xmlSerializer.read(xmlSerializer.write(JSONSerializer.toJSON(<span style="color:#006080;">"['json','is','easy']"</span>)).toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    s = (String[]) JSONArray.toArray(jsonArray, String.<span style="color:#0000ff;">class</span>);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(s[1].toString());</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>      </div>     </div>     <p>主要运用到XMLSerializer的read方法,将xml内容读取后,转换成Java对象。运行后结果如下: </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">============== XML >>>> Java String Array ==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">[<span style="color:#006080;">"a"</span>,<span style="color:#006080;">"b"</span>,<span style="color:#006080;">"c"</span>]</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">a</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">============== XML >>>> Java <span style="color:#0000ff;">boolean</span> Array ==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">[Z@15856a5</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">true</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">[Z@79ed7f</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">true</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java Object Array >>> JSON Array ==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">1</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">a</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">true</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">[<span style="color:#006080;">"a"</span>,<span style="color:#006080;">"b"</span>,<span style="color:#006080;">"c"</span>]</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">true</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">[<span style="color:#006080;">"true"</span>,<span style="color:#006080;">"false"</span>,<span style="color:#006080;">"true"</span>]</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==============Java String >>> JSON ==================</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">json</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">net.sf.ezmorph.bean.MorphDynaBean@c09554[</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  {json=is easy}</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">]</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">is</pre>      </div>     </div>     <p>3、 将xml的字符串内容,转换成Java的Array对象 </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> testReadXml2Array() {</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    String str = <span style="color:#006080;">"<a class=\"array\">"</span> +   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">          <span style="color:#006080;">"<e type=\"function\" params=\"i,j\">"</span> +  </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">          <span style="color:#006080;">"return matrix[i][j];"</span> +    </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">          <span style="color:#006080;">"</e>"</span> +  </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;">"</a>"</span>;</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    JSONArray json = (JSONArray) <span style="color:#0000ff;">new</span> XMLSerializer().read(str);</pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(json.toString());   </pre>       <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>      </div>     </div>     <p>上面是一段xml字符串格式的文档,将其转换为JSONArray对象。转换后结果如下: </p>     <div id="codeSnippetWrapper">      <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">       <pre>[function(i,j){ <span style="color:#0000ff;">return</span> matrix[i][j]; }]</pre>      </div>     </div>     <p>就是一个数组;<br /> <br /> 转自:<a href="/misc/goto?guid=4959517669369625344" target="_blank">http://www.cnblogs.com/hoojo/archive/2011/04/21/2023805.html</a></p>    </div>