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

<channel>
	<title>fatkun&#039;s blog &#187; JSONObject</title>
	<atom:link href="http://fatkun.com/tag/jsonobject/feed" rel="self" type="application/rss+xml" />
	<link>http://fatkun.com</link>
	<description>又一个 WordPress 站点</description>
	<lastBuildDate>Sat, 19 May 2012 17:25:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>使用json-lib遍历数组与对象（JSONArray与JSONObject）</title>
		<link>http://fatkun.com/2010/07/jsonarray-jsonobject-array.html</link>
		<comments>http://fatkun.com/2010/07/jsonarray-jsonobject-array.html#comments</comments>
		<pubDate>Sun, 18 Jul 2010 06:55:31 +0000</pubDate>
		<dc:creator>fatkun</dc:creator>
				<category><![CDATA[J2EE]]></category>
		<category><![CDATA[JSONArray]]></category>
		<category><![CDATA[JSONObject]]></category>
		<category><![CDATA[遍历数组]]></category>

		<guid isPermaLink="false">http://fatkun.com/?p=479</guid>
		<description><![CDATA[使用json-lib遍历数组与对象 //遍历json数组 String json1 = &#34;{data:[{name:'Wallace'},{name:'Grommit'}]}&#34;; jsonObjSplit = new JSONObject&#40;json1&#41;; JSONArray ja = jsonObjSplit.getJSONArray&#40;&#34;data&#34;&#41;; for &#40;int i = 0; i &#60; ja.length&#40;&#41;; i++&#41; &#123; JSONObject jo = &#40;JSONObject&#41; ja.get&#40;i&#41;; System.out.println&#40;jo.get&#40;&#34;name&#34;&#41;&#41;; &#125; &#160; //JSONObject遍历json对象 String json2 = &#34;{name:'Wallace',age:15}&#34;; jsonObj = new JSONObject&#40;json2&#41;; &#160; for &#40;Iterator iter = jsonObj.keys&#40;&#41;; iter.hasNext&#40;&#41;;&#41; &#123; String key = &#40;String&#41;iter.next&#40;&#41;; System.out.println&#40;jsonObj .getString&#40;Key&#41;&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p style="padding: 0px; margin: 0px;">使用json-lib遍历数组与对象</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//遍历json数组</span>
<span style="color: #003399;">String</span> json1 <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;{data:[{name:'Wallace'},{name:'Grommit'}]}&quot;</span><span style="color: #339933;">;</span>
jsonObjSplit <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span>json1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
JSONArray ja <span style="color: #339933;">=</span> jsonObjSplit.<span style="color: #006633;">getJSONArray</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;data&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> ja.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
JSONObject jo <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>JSONObject<span style="color: #009900;">&#41;</span> ja.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>jo.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//JSONObject遍历json对象</span>
<span style="color: #003399;">String</span> json2 <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;{name:'Wallace',age:15}&quot;</span><span style="color: #339933;">;</span>
jsonObj <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span>json2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Iterator</span> iter <span style="color: #339933;">=</span> jsonObj.<span style="color: #006633;">keys</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> iter.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003399;">String</span> key <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span>iter.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>jsonObj .<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Key</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
｝</pre></div></div>

<p style="padding: 0px; margin: 0px;">
]]></content:encoded>
			<wfw:commentRss>http://fatkun.com/2010/07/jsonarray-jsonobject-array.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

