<?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>爱周末 &#187; JSON.parseObject</title>
	<atom:link href="http://zhoumo123.cn/tag/json-parseobject/feed" rel="self" type="application/rss+xml" />
	<link>http://zhoumo123.cn</link>
	<description>知识分享，共同进步。zhoumo123.cn</description>
	<lastBuildDate>Thu, 07 Nov 2019 05:53:49 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.0.1</generator>
	<item>
		<title>JSON.parseObject(json字符串，对象.class)将str转对象 (JSONObject.parseObject)</title>
		<link>http://zhoumo123.cn/java/3626.html</link>
		<comments>http://zhoumo123.cn/java/3626.html#comments</comments>
		<pubDate>Wed, 20 Dec 2017 03:18:59 +0000</pubDate>
		<dc:creator><![CDATA[zhangc]]></dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JSON.parseObject]]></category>

		<guid isPermaLink="false">http://zhoumo123.cn/?p=3626</guid>
		<description><![CDATA[将JSON字符串转换成java中的POJO对象。在fastJson中已经有提供好的方法：JSON.parseObject(json字符串，对象.class);使用方式如下： 运行后结果如下： Name = james, age = 12 使用jar包：fastjson-1.1.36.jar包 parseObject(String str)的作用 JSON.parseObject（String str）是将str转化为相应的JSONObject对象，其中str是“键值对”形式的json字符串，转化为JSONObject对象之后就可以使用其内置的方法，进行各种处理了。 JSON.parseObje ...  <a href="http://zhoumo123.cn/java/3626.html">  阅读全文 </a>]]></description>
				<content:encoded><![CDATA[<p>将JSON字符串转换成java中的POJO对象。在fastJson中已经有提供好的方法：<strong>JSON.parseObject</strong>(json字符串，对象.class);使用方式如下：</p>
<pre class="brush: java; title: ; notranslate">
package json;

import com.alibaba.fastjson.JSON;

public class TestJson {

    String name;
    String age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public static void main(String[] args) {
        String jsonStr = &quot;{\&quot;name\&quot;:\&quot;james\&quot;, \&quot;age\&quot;:12}&quot;;
        TestJson test = JSON.parseObject(jsonStr, TestJson.class);
        System.out.printf(&quot;Name = %s, age = %s&quot;, test.getName(), test.getAge());
    }
}
</pre>
<p><strong>运行后结果如下：</strong></p>
<p>Name = james, age = 12<br />
使用jar包：fastjson-1.1.36.jar包</p>
<p><strong>parseObject(String str)的作用</strong><br />
JSON.parseObject（String str）是将str转化为相应的JSONObject对象，其中str是“键值对”形式的json字符串，转化为JSONObject对象之后就可以使用其内置的方法，进行各种处理了。</p>
<p><strong>JSON.parseObject(String str)与 JSONObject.parseObject(String str)的区别</strong><br />
根据源码显示：JSON是一个抽象类，JSON中有一个静态方法parseObject（String text），将text解析为一个JSONObject对象并返回；JSONObject是一个继承自JSON的类，当调用JSONObject.parseObject（result）时，会直接调用父类的parseObject（String text）。所以两者没什么区别，一个是用父类去调用父类自己的静态的parseObject（String text），一个是用子类去调用父类的静态parseObject（String text），两者调的是同一个方法。</p>
<p>参考：</p>
<p>https://segmentfault.com/q/1010000005733442</p>
<p>http://blog.csdn.net/dafeige8/article/details/73924034</p>
]]></content:encoded>
			<wfw:commentRss>http://zhoumo123.cn/java/3626.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
