﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-yxj1314520</title><link>http://www.blogjava.net/yxj1314520/</link><description /><language>zh-cn</language><lastBuildDate>Sun, 05 Apr 2026 14:45:21 GMT</lastBuildDate><pubDate>Sun, 05 Apr 2026 14:45:21 GMT</pubDate><ttl>60</ttl><item><title>SSH 显示中文乱码 </title><link>http://www.blogjava.net/yxj1314520/archive/2013/09/12/404000.html</link><dc:creator>姚先进</dc:creator><author>姚先进</author><pubDate>Thu, 12 Sep 2013 09:23:00 GMT</pubDate><guid>http://www.blogjava.net/yxj1314520/archive/2013/09/12/404000.html</guid><wfw:comment>http://www.blogjava.net/yxj1314520/comments/404000.html</wfw:comment><comments>http://www.blogjava.net/yxj1314520/archive/2013/09/12/404000.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yxj1314520/comments/commentRss/404000.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yxj1314520/services/trackbacks/404000.html</trackback:ping><description><![CDATA[<div>试了N多方法，貌似在终端执行命令：<br /> export LC_ALL=zh_CN.GB2312;export LANG=zh_CN.GB2312是最有效的。<br /> =======================<br /> 1.不管用那种ssh客户端，字体设定一定要设为可以显示中文的字体。<br /> <br /> 2.远程的locale一定要设置为LANG=zh_CN.UTF-8<br /> <br /> ========================================<br /> 修改/etc/profile <br /> <br /> 增加这一行<br /> export LC_ALL=zh_CN.GBK<br /> <br /> ========================================<br /> <br /> SSH显示中文乱码问题<br /> (1) 打开/etc/sysconfig/i18n<br /> 设置为：<br /> LANG="zh_CN.GB2312"<br /> LANGUAGE="zh_CN.GB18030:zh_CN.GB2312:zh_CN"<br /> SUPPORTED="zh_CN.GB18030:zh_CN.GB2312:zh_CN.UTF-8:zh:en_US.UTF-8:en_US:en:ja_JP.UTF-8:ja_JP:ja"<br /> SYSFONT="lat0-sun16"<br /> SYSFONTACM="8859-15"<br /> <br /> 其中LANG="zh_CN.GB2312" 是必须的(如果你不想让中文乱码的话!!!)<br /> 其它的可以按照自已的需求来改变。<br /> (2) 打开smb.conf<br /> 添加：<br /> <br /> &nbsp;&nbsp; display charset=cp936<br /> &nbsp;&nbsp;&nbsp; unix charset=cp936<br /> &nbsp;&nbsp;&nbsp; doc&nbsp; charset=cp936<br /> ========================</div><img src ="http://www.blogjava.net/yxj1314520/aggbug/404000.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yxj1314520/" target="_blank">姚先进</a> 2013-09-12 17:23 <a href="http://www.blogjava.net/yxj1314520/archive/2013/09/12/404000.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MyBatis collection的两种形式——MyBatis学习笔记之九 </title><link>http://www.blogjava.net/yxj1314520/archive/2013/09/11/403951.html</link><dc:creator>姚先进</dc:creator><author>姚先进</author><pubDate>Wed, 11 Sep 2013 05:44:00 GMT</pubDate><guid>http://www.blogjava.net/yxj1314520/archive/2013/09/11/403951.html</guid><wfw:comment>http://www.blogjava.net/yxj1314520/comments/403951.html</wfw:comment><comments>http://www.blogjava.net/yxj1314520/archive/2013/09/11/403951.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yxj1314520/comments/commentRss/403951.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yxj1314520/services/trackbacks/403951.html</trackback:ping><description><![CDATA[<div>&nbsp;与association一样，collection元素也有两种形式，现介绍如下：<div><span style="font-size:16px"><strong>一、嵌套的resultMap</strong></span></div><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;实际上以前的示例使用的就是这种方法，今天介绍它的另一种写法。还是以教师映射为例，修改映射文件TeacherMapper.xml如下（<a href="http://down.51cto.com/data/504573" target="_blank">点击此处进入嵌套resultMap形式的示例源码下载页面</a>。注：本示例代码是在修改本系列的上篇博文示例代码的基础上完成的，用到了MapperScannerConfigurer和注解等知识。对这些知识不熟悉的读者，可参考上篇博文：<a href="http://legend2011.blog.51cto.com/3018495/980150">http://legend2011.blog.51cto.com/3018495/980150</a>）：</p><pre><ol list-paddingleft-2"=""><li><p>&lt;?xmlversion="1.0"encoding="utf8"?&gt;</p></li><li><p>&lt;!DOCTYPE&nbsp;mapper&nbsp;PUBLIC&nbsp;"-//mybatis.org//DTD&nbsp;Mapper&nbsp;3.0//EN"&nbsp;"http://mybatis.org/dtd/mybatis-3-mapper.dtd"&gt;</p></li><li><p>&lt;!--与以前一样，namespace的值是对应的映射器接口的完整名称--&gt;</p></li><li><p>&lt;mappernamespace="com.abc.mapper.TeacherMapper"&gt;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--TeacherMapper接口中getById方法对应的SQL语句。&nbsp;&nbsp;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;查询教师及其指导的学生的信息。由于教师、学生都有&nbsp;&nbsp;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;id、name、gender等属性，因此给教师的字段都起了别名--&gt;</p></li><li><p>&lt;selectid="getById"parameterType="int"resultMap="supervisorResultMap"&gt;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select&nbsp;t.id&nbsp;t_id,&nbsp;t.name&nbsp;t_name,&nbsp;t.gender&nbsp;t_gender,&nbsp;&nbsp;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.research_area&nbsp;t_research_area,&nbsp;t.title&nbsp;t_title,&nbsp;&nbsp;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.id,s.name,&nbsp;s.gender,s.major,s.grade&nbsp;&nbsp;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;teacher&nbsp;t,student&nbsp;s&nbsp;where&nbsp;t.id=#{id}&nbsp;&nbsp;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;and&nbsp;s.supervisor_id&nbsp;=&nbsp;t.id&nbsp;&nbsp;</p></li><li><p>&lt;/select&gt;</p></li><li><p>&lt;!--教师实体映射--&gt;</p></li><li><p>&lt;resultMapid="supervisorResultMap"type="Teacher"&gt;</p></li><li><p>&lt;idproperty="id"column="t_id"/&gt;</p></li><li><p>&lt;resultproperty="name"column="t_name"/&gt;</p></li><li><p>&lt;resultproperty="gender"column="t_gender"/&gt;</p></li><li><p>&lt;resultproperty="researchArea"column="t_research_area"/&gt;</p></li><li><p>&lt;resultproperty="title"column="t_title"/&gt;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--需要注意的是，上面的select语句中学生的字段名/别名应与&nbsp;&nbsp;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;下面的column属性一致。ofType指collection包含的元素的类型，&nbsp;&nbsp;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;此属性不可少--&gt;</p></li><li><p>&lt;collectionproperty="supStudents"ofType="Student"&gt;</p></li><li><p>&lt;idproperty="id"column="id"/&gt;</p></li><li><p>&lt;resultproperty="name"column="name"/&gt;</p></li><li><p>&lt;resultproperty="gender"column="gender"/&gt;</p></li><li><p>&lt;resultproperty="major"column="major"/&gt;</p></li><li><p>&lt;resultproperty="grade"column="grade"/&gt;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--映射学生的指导教师属性，用到了&nbsp;&nbsp;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;supervisorResultMap本身--&gt;</p></li><li><p>&lt;associationproperty="supervisor"</p></li><li><p>resultMap="supervisorResultMap"/&gt;</p></li><li><p>&lt;/collection&gt;</p></li><li><p>&lt;/resultMap&gt;</p></li><li><p>&lt;/mapper&gt;</p></li></ol></pre><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;运行程序结果如下：&nbsp;</p><p style="text-align:center"><a href="http://img1.51cto.com/attachment/201209/184504630.png" target="_blank"><img src="http://img1.51cto.com/attachment/201209/184504630.png" border="0" width="650"  alt="" /></a></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;与以前的写法相比，这种写法的缺点是学生实体映射被嵌入到教师实体映射中，因此学生实体映射不能被重用。</p><p><span style="font-size:16px"><span style="font-family:黑体"><strong>二、嵌套的select语句</strong></span></span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;这种方式是使用一条单独的select语句来加载关联的实体（在本例中就是学生实体），然后在collection元素中引用此select语句（注：此方法会产生N+1问题，关于这个问题可参考本系列博客中的&#8220;<a href="http://legend2011.blog.51cto.com/3018495/1131629" target="_blank">MyBatis中的N+1问题</a>&#8221;）。首先修改TeacherMapper.xml如下（<a href="http://down.51cto.com/data/504574" target="_blank">点击此处进入嵌套select语句形式示例源码下载页面</a>）：</p><pre><ol list-paddingleft-2"=""><li><p>&lt;?xmlversion="1.0"encoding="utf8"?&gt;</p></li><li><p>&lt;!DOCTYPE&nbsp;mapper&nbsp;PUBLIC&nbsp;"-//mybatis.org//DTD&nbsp;Mapper&nbsp;3.0//EN"&nbsp;"http://mybatis.org/dtd/mybatis-3-mapper.dtd"&gt;</p></li><li><p>&lt;!--与以前一样，namespace的值是对应的映射器接口的完整名称--&gt;</p></li><li><p>&lt;mappernamespace="com.abc.mapper.TeacherMapper"&gt;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--TeacherMapper接口中getById方法对应的SQL语句。&nbsp;&nbsp;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;查询教师的信息。--&gt;</p></li><li><p>&lt;selectid="getById"parameterType="int"resultMap="supervisorResultMap"&gt;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select&nbsp;*&nbsp;from&nbsp;teacher&nbsp;where&nbsp;id=#{id}&nbsp;&nbsp;</p></li><li><p>&lt;/select&gt;</p></li><li><p>&lt;!--教师实体映射--&gt;</p></li><li><p>&lt;resultMapid="supervisorResultMap"type="Teacher"&gt;</p></li><li><p>&lt;idproperty="id"column="id"/&gt;</p></li><li><p>&lt;resultproperty="name"column="name"/&gt;</p></li><li><p>&lt;resultproperty="gender"column="gender"/&gt;</p></li><li><p>&lt;resultproperty="researchArea"column="research_area"/&gt;</p></li><li><p>&lt;resultproperty="title"column="title"/&gt;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--ofType指collection包含的元素的类型，此属性不可少。&nbsp;&nbsp;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;column属性指把上述的getById的select语句中的教师id列的值作为参数&nbsp;&nbsp;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;传递给将要引用到的下述的getStudents的select语句，此属性不可少。&nbsp;&nbsp;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;引用的形式为：命名空间.select语句id--&gt;</p></li><li><p>&lt;collectionproperty="supStudents"column="id"ofType="Student"</p></li><li><p>select="com.abc.mapper.StudentMapper.getStudents"/&gt;</p></li><li><p>&lt;/resultMap&gt;</p></li><li><p>&lt;/mapper&gt;</p></li></ol></pre><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;在这里把根据指导教师id查询学生信息的SQL语句写在StudentMapper.xml中，并引用其中的学生实体映射studentResultMap。修改StudentMapper.xml如下：</p><pre><ol list-paddingleft-2"=""><li><p>&lt;?xmlversion="1.0"encoding="utf8"?&gt;</p></li><li><p>&lt;!DOCTYPE&nbsp;mapper&nbsp;PUBLIC&nbsp;"-//mybatis.org//DTD&nbsp;Mapper&nbsp;3.0//EN"&nbsp;"http://mybatis.org/dtd/mybatis-3-mapper.dtd"&gt;</p></li><li><p>&lt;mappernamespace="com.abc.mapper.StudentMapper"&gt;</p></li><li><p>&lt;resultMapid="studentResultMap"type="Student"&gt;</p></li><li><p>&lt;idproperty="id"column="id"/&gt;</p></li><li><p>&lt;resultproperty="name"column="name"/&gt;</p></li><li><p>&lt;resultproperty="gender"column="gender"/&gt;</p></li><li><p>&lt;resultproperty="major"column="major"/&gt;</p></li><li><p>&lt;resultproperty="grade"column="grade"/&gt;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--在这里引用supervisorResultMap和getById，亦采用&nbsp;&nbsp;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;命名空间名.相关元素id的形式。column="supervisor_id"</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;属性不可少--&gt;</p></li><li><p>&lt;associationproperty="supervisor"</p></li><li><p>resultMap="com.abc.mapper.TeacherMapper.supervisorResultMap"</p></li><li><p>select="com.abc.mapper.TeacherMapper.getById"column="supervisor_id"/&gt;</p></li><li><p>&lt;/resultMap&gt;</p></li><li><p>&lt;!--根据指导教师id查询学生信息--&gt;</p></li><li><p>&lt;selectid="getStudents"parameterType="int"</p></li><li><p>resultMap="studentResultMap"&gt;</p></li><li><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select&nbsp;*&nbsp;from&nbsp;student&nbsp;where&nbsp;supervisor_id&nbsp;=&nbsp;#{id}&nbsp;&nbsp;</p></li><li><p>&lt;/select&gt;</p></li><li><p>&lt;/mapper&gt;</p></li></ol></pre><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;执行结果如下：</p><p style="text-align:center"><a href="http://img1.51cto.com/attachment/201209/190427604.png" target="_blank"><img src="http://img1.51cto.com/attachment/201209/190427604.png" border="0" width="650"  alt="" /></a></p></div><img src ="http://www.blogjava.net/yxj1314520/aggbug/403951.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yxj1314520/" target="_blank">姚先进</a> 2013-09-11 13:44 <a href="http://www.blogjava.net/yxj1314520/archive/2013/09/11/403951.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL：不存在则insert存在则update </title><link>http://www.blogjava.net/yxj1314520/archive/2013/09/10/403915.html</link><dc:creator>姚先进</dc:creator><author>姚先进</author><pubDate>Tue, 10 Sep 2013 10:56:00 GMT</pubDate><guid>http://www.blogjava.net/yxj1314520/archive/2013/09/10/403915.html</guid><wfw:comment>http://www.blogjava.net/yxj1314520/comments/403915.html</wfw:comment><comments>http://www.blogjava.net/yxj1314520/archive/2013/09/10/403915.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yxj1314520/comments/commentRss/403915.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yxj1314520/services/trackbacks/403915.html</trackback:ping><description><![CDATA[<div><p>最近在工作中遇到了一个需求</p> <p>在执行数据库操作时需要先判断指定的数据是否存在，如果不存在则插入，存在则更新</p> <p>最开始使用的是三条SQL语句：</p>  <div bg_sql"=""><div><div><strong>[sql]</strong> <a href="http://blog.csdn.net/frank59/article/details/7843137#" title="view plain">view plain</a><a href="http://blog.csdn.net/frank59/article/details/7843137#" title="copy">copy</a></div></div><ol start="1"><li><span>SELECT&nbsp;bl_count,bl_src,bl_date,bl_topic&nbsp;FROM&nbsp;temp_table&nbsp;WHERE&nbsp;bl_topic=?&nbsp;AND&nbsp;bl_src=?&nbsp;AND&nbsp;bl_date=?;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;</li><li><span>UPDATE&nbsp;temp_table&nbsp;SET&nbsp;bl_count=?&nbsp;WHERE&nbsp;bl_topic=?&nbsp;AND&nbsp;bl_src=?&nbsp;AND&nbsp;bl_date=?;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;</li><li><span>INSERT&nbsp;INTO&nbsp;temp_table&nbsp;(bl_src,bl_date,bl_count,bl_topic)&nbsp;values(?,?,?,?)&nbsp;&nbsp;</span></li></ol></div>逻辑是：  <div bg_java"=""><div><div><strong>[java]</strong> <a href="http://blog.csdn.net/frank59/article/details/7843137#" title="view plain">view plain</a><a href="http://blog.csdn.net/frank59/article/details/7843137#" title="copy">copy</a></div></div><ol start="1"><li><span>if(SELECT!=&nbsp;null){&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;UPDATE&nbsp;&nbsp;</li><li>}<span>else{&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;INSERT&nbsp;&nbsp;</li><li>}&nbsp;&nbsp;</li></ol></div><br /> <p>后来leader提示还有新的方法，一条SQL语句就能搞定：</p>  <div bg_sql"=""><div><div><strong>[sql]</strong> <a href="http://blog.csdn.net/frank59/article/details/7843137#" title="view plain">view plain</a><a href="http://blog.csdn.net/frank59/article/details/7843137#" title="copy">copy</a></div></div><ol start="1"><li><span>INSERT&nbsp;INTO&nbsp;temp_table(bl_src,bl_date,bl_count,bl_topic)&nbsp;VALUES(?,?,?,?)&nbsp;ON&nbsp;DUPLICATE&nbsp;KEY&nbsp;UPDATE&nbsp;bl_count=bl_count+?;&nbsp;&nbsp;</span></li></ol></div><br /> 但是有个前提就是：什么时候会执行update语句？在SQL语句中并没有条件。  <p>后来在网上看到的，<span style="color:#ff0000">执行update语句的条件是insert语句的执行会造成唯一键的重复。</span></p> <p>所以，<span style="color:#ff0000">在创建表的时候还要加上唯一键的约束</span>：</p>  <div bg_sql"=""><div><div><strong>[sql]</strong> <a href="http://blog.csdn.net/frank59/article/details/7843137#" title="view plain">view plain</a><a href="http://blog.csdn.net/frank59/article/details/7843137#" title="copy">copy</a></div></div><ol start="1"><li><span>ALTER&nbsp;TABLE&nbsp;temp_table&nbsp;ADD&nbsp;CONSTRAINT&nbsp;c_topic_src_date&nbsp;UNIQUE(bl_topic,bl_src,bl_date);&nbsp;&nbsp;</span></li></ol></div>  <p>这样就能达到目的。</p></div><img src ="http://www.blogjava.net/yxj1314520/aggbug/403915.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yxj1314520/" target="_blank">姚先进</a> 2013-09-10 18:56 <a href="http://www.blogjava.net/yxj1314520/archive/2013/09/10/403915.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JSP:include的flush属性的作用 </title><link>http://www.blogjava.net/yxj1314520/archive/2013/07/29/402131.html</link><dc:creator>姚先进</dc:creator><author>姚先进</author><pubDate>Mon, 29 Jul 2013 12:54:00 GMT</pubDate><guid>http://www.blogjava.net/yxj1314520/archive/2013/07/29/402131.html</guid><wfw:comment>http://www.blogjava.net/yxj1314520/comments/402131.html</wfw:comment><comments>http://www.blogjava.net/yxj1314520/archive/2013/07/29/402131.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/yxj1314520/comments/commentRss/402131.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yxj1314520/services/trackbacks/402131.html</trackback:ping><description><![CDATA[<div>          <h3>         <span><a href="http://blog.csdn.net/zw_2011/article/details/7431360">         JSP:include的flush属性的作用         </a></span>     </h3> </div>               <div>         <span>         分类：             <a href="http://blog.csdn.net/zw_2011/article/category/1313184">其他</a>          </span>     2012-04-06 10:51     <span title="阅读次数">2572人阅读</span>     <span title="评论次数"><a href="http://blog.csdn.net/zw_2011/article/details/7431360#comments">评论</a>(2)</span>     <a title="收藏">收藏</a>     <a href="http://blog.csdn.net/zw_2011/article/details/7431360#report" title="举报">举报</a>      </div> <div><a href="http://blog.csdn.net/tag/details.html?tag=include" target="_blank">include</a><a href="http://blog.csdn.net/tag/details.html?tag=jsp" target="_blank">jsp</a><a href="http://blog.csdn.net/tag/details.html?tag=servlet" target="_blank">servlet</a><a href="http://blog.csdn.net/tag/details.html?tag=%e6%9c%8d%e5%8a%a1%e5%99%a8" target="_blank">服务器</a><a href="http://blog.csdn.net/tag/details.html?tag=%e6%b5%8f%e8%a7%88%e5%99%a8" target="_blank">浏览器</a></div>        <div id="article_content">  <span style="color:#000000"><span style="background-color:#ffffff"><span style="font-size:18px"><strong>JSP</strong> 中<span style="background-color:#99ff99; color:black">include</span> 另一个文件时有个很偏的属性，叫<span style="background-color:#ff9999; color:black">flush</span>，默认为  false。</span></span></span> <div><br /> </div> <div><span style="font-size:18px; color:#000000; background-color:#ffffff">在同一个 <span style="background-color:#ffff66; color:black"> JSP</span> 中，如果不断 <span style="background-color:#99ff99; color:black">include</span> 自己（源文件），在逻辑上会形成死循环。若默认情况下，服务器会等待该文件被读到底端，然后才输出到客户端，并且销毁该次访问的 request 和 response。而当把<span style="background-color:#ff9999; color:black">flush</span> 属性赋为真值时，在缓存累积了一定数据时，服务器会先提供一部分数据给浏览器，并等待后续内容。</span></div> <div><span style="color:#000000"><br /> </span></div> <div><span style="font-size:18px; color:#000000; background-color:#ffffff">由此可以得出结论，在简单页面中，该属性不纳入考虑，而在页面包含大量数据时，为缩短客户端延迟，可将一部分内容先行输出。该属性在 Servlet 中也有对应的应用。</span></div>  </div>  <img src ="http://www.blogjava.net/yxj1314520/aggbug/402131.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yxj1314520/" target="_blank">姚先进</a> 2013-07-29 20:54 <a href="http://www.blogjava.net/yxj1314520/archive/2013/07/29/402131.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>android 开发问题集锦</title><link>http://www.blogjava.net/yxj1314520/archive/2013/05/17/399423.html</link><dc:creator>姚先进</dc:creator><author>姚先进</author><pubDate>Fri, 17 May 2013 08:57:00 GMT</pubDate><guid>http://www.blogjava.net/yxj1314520/archive/2013/05/17/399423.html</guid><wfw:comment>http://www.blogjava.net/yxj1314520/comments/399423.html</wfw:comment><comments>http://www.blogjava.net/yxj1314520/archive/2013/05/17/399423.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yxj1314520/comments/commentRss/399423.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yxj1314520/services/trackbacks/399423.html</trackback:ping><description><![CDATA[<div><div>     		  <p>&nbsp;<strong>大家都在为项目开发成功而喜悦，但可不知成功的路上是会经常出错的，下面是我碰到的一些错误集合！</strong></p> <p>【错误信息】</p> <p>01-16 17:16:18.945: I/magh(979): org.apache.http.conn.HttpHostConnectException: Connection to http://127.0.0.1:8080 refused </p><p>在android模拟器连接本机访问web时报这错，把127.0.0.1改成localhost也是一样的</p> 原因：<br /> &nbsp;在向本机发送HTTP请求时，有一点必须注意，就是在android <a href="http://www.2cto.com/os/xuniji/" target="_blank">虚拟机</a>中，<span style="color: #ff0000; ">127.0.0.1</span>为android  虚拟机的IP地址，如果要访问本机，IP地址应该改为<span style="color: #ff0000; ">10.0.2.2</span>。否则肯定会导致访问不成功！<br /> ==========================================================================<br /> 【错误信息】<br /> [2011-01-19 16:39:10 - ApiDemos] WARNING:  Application does not specify an API level requirement!<br /> [2011-01-19 16:39:10 -  ApiDemos] Device API version is 8 (Android 2.2)<br /> 原因：<br /> 不影响正常运行。在AndroidManifest.xml文件中没有加API的版本号，在&lt;manifest&gt;   &lt;/manifest&gt; 之间加&lt;uses-sdk   android:minSdkVersion="3"&gt;&lt;/uses-sdk&gt;<br /> [2011-01-19 16:55:04 -  ApiDemos] Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE<br /> [2011-01-19  16:55:04 - ApiDemos] Please check logcat output for more details.<br /> [2011-01-19  16:55:05 - ApiDemos] Launch canceled!<br /> 该设备没有足够的存储空间来安装应用程序，<br /> <br /> <br /> 【错误信息】<br /> [2011-02-18 11:46:53] Failed to push selection:  Is a directory<br /> 原因：<br /> 原先目录已经有pkg_3.apk的文件夹，再copy一个pkg_3.apk安装文件时出现问题，解决办法，先删除掉pkg_3.apk的文件夹<br /> [2011-03-04 09:25:12 - ActivityMain]: Dx<br /> UNEXPECTED TOP-LEVEL  EXCEPTION:<br /> java.lang.IllegalArgumentException: already added:  Lorg1/apache/commons/codec/net/RFC1522Codec;<br /> [2011-03-04 09:25:12 -  ActivityMain]: Dx at  com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)<br /> [2011-03-04  09:25:12 - ActivityMain]: Dx at  com.android.dx.dex.file.DexFile.add(DexFile.java:143)<br /> .....<br /> [2011-03-04 09:25:12 - ActivityMain]: Dx1 error;  aborting<br /> [2011-03-04 09:25:12 - ActivityMain] Conversion to Dalvik format  failed with error 1<br /> 原因：<br /> <br /> <br /> 【错误信息】<br /> 启动Eclipse时出现：<br /> this  android sdk requires android developer toolkit version 10.0.0 or  above.<br /> current version is 8.0.1.v201012062107-82219.<br /> please update adt to  the latest version<br /> <img id="aimg_UF29F" alt="" _load="1" src="http://www.51laifu.cn/upload/2012/07/04/20120704155743140.gif" border="0" /><br /> 原因：<br /> Eclipse的android开发插件版本过低，应该下载ADT-10.0.0，并且<br /> 1. 启动  Eclipse, 然后进入 Help &gt; Install New Software.<br /> 2. 在 Available Software  对话框里，点击 Add....<br /> <br /> <br /> 【错误信息】<br /> [2011-03-09  15:21:34 - Info] Failed to install Info.apk on device '?': Unable to open sync  connection!<br /> [2011-03-09 15:21:34 - Info] java.io.IOException: Unable to open  sync connection!<br /> [2011-03-09 15:21:34 - Info] Launch canceled!<br /> 原因：<br /> 关闭模拟器和eclipse，执行adb  kill-server命令，然后重试一下<br /> <br /> <br /> 【错误信息】<br /> 调用Webservice时出现<br /> java.net.SocketException:  Permission denied (maybe missing INTERNET permission)<br /> 原因:<br /> 需要访问到网络，所以，在AndroidManifest.xml中，需要进行如下配置：  <br /> &lt;uses-permission android:name="android.permission.INTERNET"  /&gt;<br /> <br /> <br /> 【错误信息】<br /> org.xmlpull.v1.XmlPullParserException: expected:  START_TAG  {http://schemas.xmlsoap.org/soap/envelope/}Envelope  (position:START_TAG  &lt;{http://schemas.xmlsoap.org/wsdl/}wsdl:definitions   targetNamespace='http://bo.webservice.nqbx.nq.com'&gt;@2:603   injava.io.InputStreamReader@44a3a7b0)<br /> 原因有可能是以下2个之一:<br /> 1）Webservice服务器的Soap版本为1.0，所以客户端指定<br /> SoapSerializationEnvelope envelope = new  SoapSerializationEnvelope(SoapEnvelope.VER11);<br /> VER11改为VER10<br /> 2）String serviceUrl =  "http://200.200.200.11:10000/nqbx/service/InqBxWebService?wsdl";<br /> Url指的是你的webservice的地址.一般都是以***.wsdl或者***.?wsdl结束的...但是.需要注意的是..要去掉后面的.wsdl或者.?wsdl<br /> <br /> <br /> 【错误信息】<br /> 在新的线程中 public class  HttpThread extends Thread {...}<br /> 增加一个弹出窗体：<br /> new   AlertDialog.Builder(this).setTitle("数据加载失败").setMessage("请检查网络连接情况")&nbsp; &nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;.setPositiveButton("OK", new DialogInterface.OnClickListener(){&nbsp;  &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;  &nbsp;public void onClick(DialogInterface dialoginterface, int i)&nbsp;  &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;{&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;  &nbsp;&nbsp; &nbsp;}&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}).show();&nbsp; &nbsp;&nbsp;&nbsp;<br /> &nbsp;&nbsp;原因及解决办法：<br /> //不能在线程中操作UI界面<br /> java.lang.RuntimeException: Can't create handler inside thread  that has not called Looper.prepare()<br /> <br /> 修改后：<br /> new   AlertDialog.Builder(com.nantsing.infoquery.chuanbo_detail.this).setTitle(" 数据加载失败").setMessage("请检查网络连接情况")&nbsp;  &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;.setPositiveButton("OK", new  DialogInterface.OnClickListener(){&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;  &nbsp;&nbsp; &nbsp;public void  onClick(DialogInterface dialoginterface, int i)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;{&nbsp; &nbsp;&nbsp;  &nbsp;&nbsp; &nbsp;&nbsp;  &nbsp;}<br /> <br /> <br /> 【错误信息】<br /> The constructor  AlertDialog.Builder(chuanbo_detail.HttpThread) is undefined <br /> 原因及解决办法：<br /> 在UI主线程之外是无法对UI组件进行控制的。因为你必须在新线程任务完成之后利用各种方法先UI主线程发送消息通知任务完成从而来显示各种提示消息。<br /> 线程间通信方法有多种，常用的是用handler来传递消息。<br /> 如下：<br /> 线程中构造消息：<br /> //构造消息Message  message = handle.obtainMessage();Bundle b = new  Bundle();b.putString("tag",   "1");message.setData(b);handle.sendMessage(message); <br /> 另外自定义消息：<br /> &nbsp; &nbsp; &nbsp; &nbsp; /**  * 捕获消息队列 fubin.pan 2011-04-02 */Handler handler = new  Handler() {public void  handleMessage(Message m) {if  (!m.getData().getString("tag").equals("1")){&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;  &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;  ...}else{new   AlertDialog.Builder(chuanbo_detail.this).setTitle("数据加载失败").setMessage(" 请检查网络连接情况！")&nbsp;  &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; .setPositiveButton("OK", new  DialogInterface.OnClickListener(){&nbsp;  &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void  onClick(DialogInterface dialoginterface, int  i)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  {&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;  }).show();}}};<br /> <br /> <br /> 【错误信息】 <br /> android低版本工程（如1.5）放到高版本环境中（如2.2）可能会上述错误，解决方法如下：<br /> 1。 如果不修改android  sdk版本，则使用project clean 命令作用于某工程即可。<br /> &nbsp; &nbsp;&nbsp; &nbsp;  （该处理方式只是在高版本中兼容了低版本工程，未真正意义上的升级）<br /> 2。 如果修改android sdk版本，则需要以下几个步骤：<br /> &nbsp; &nbsp;&nbsp; &nbsp;  1）修改SDK<br /> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 选择工程，build path --&gt; configure build path ---&gt;  library 删除引用的低版本SDK，<br /> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 然后add External JARs,选择高版本SDK,OK,保存<br /> &nbsp; &nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;2）修改classpath文件 <br /> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 该文件可能存在该项: &lt;classpathentry kind="lib"&nbsp;  &nbsp;path ="你所指定的高版本的地址"<br /> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 把她修改成&lt;classpathentry kind="con"  path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK" /&gt;<br /> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;3)  修改AndroidManifest.xml<br /> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;  在AndroidManifest.xml文件中，application标签后添加&lt;uses-sdk  android:minSdkVersion="3"&gt;&lt;/uses-sdk&gt;<br /> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;4)  修改default.properties（很重要）<br /> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;该文件最后一行（前面没用#的）target=android-3  该成target=android-8，保存。<br /> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;再看看你的工程和新建的android  2.2的工程结构就一样了。<br /> <br /> <br /> 【错误信息】<br /> 在线程debug（运行没有问题）时调用Webservice时出现：<br /> 'JDI thread evaluations' has encountered a problem<br /> Exception processing async thread queue<br /> <img id="aimg_l1Zol" alt="" _load="1" src="http://www.51laifu.cn/upload/2012/07/04/20120704155743250.gif" border="0" /><br /> <br /> Exception  processing async thread queue<br /> JDI thread  evaluations<br /> <img id="aimg_fditM" alt="" _load="1" src="http://www.51laifu.cn/upload/2012/07/04/20120704155743343.gif" border="0" /><br /> <br /> 原因及解决办法：<br /> 与运行无关的错误，关掉'expressions'视图就可以了<br /> <br /> <br /> 【错误信息】<br /> 打开开源项目JavaEye Android client时出错<br /> http://javaeye-android-client.googlecode.com/svn/trunk/<br /> 这是  JavaEye 网站基于 Android 平台的客户端软件，可用以阅读动静、帖子、闲谈, 收躲, RSS 等功用。<br /> <br /> [2011-04-19 10:55:11 - JavaEye Android Client] Project has no  default.properties file! Edit the project properties to set  one.<br /> <br /> <br /> 原因及解决办法：<br /> 遇到这种情况，可以创建一个default.properties文件，如果创建之后还是有错误，那么delete这个project，重新import。<br /> 编辑default.properties  之后，一般会自动创建 gen 目录， 如果没有，也可尝试手工创建。<br /> <br /> ✿Adroid Adapter ADB  Interface 严重错误<br /> 今天在配置完Eclipse和Android   SDK开发环境之后，想用华为C8500手机通过USB连接电脑，并在手机上去调试，但莫名其妙出现Adroid Adapter ADB  Interface  安装严重错误，在豌豆荚手机精灵安装驱动的时候，也出现这个错误，后面也莫名奇妙的多装几次就好了，还没找到什么原因。<br /> <br /> <br /> 【错误信息】<br /> 用手机调试运行出现：<br /> ActivityManager: Warning: Activity not started, its current task  has been brought to the front<br /> 原因及解决办法：<br /> 该手机已经启动了相同名字的应用，关闭之后再试！<br /> <br /> <br /> 【错误信息】<br /> 最近（2012-04-05）在打开SDK  Manager.exe，更新SDK时，会出现如下错误：<br /> <img id="aimg_AYe36" alt="" _load="1" src="http://www.51laifu.cn/upload/2012/07/04/20120704155743421.jpg" border="0" width="650" /><br /> Failed to fetch URL  https://dl-ssl.google.com/android/repository/repository.xml, <br /> reason:  Connection timed out: connect<br /> 原因及解决办法：<br /> dl-ssl.google.com在大陆封掉了<br /> 解决方法就是修改<strong>C:\Windows\System32\drivers\etc\hosts</strong>文件。添加一行：<br /> 74.125.237.1&nbsp;  &nbsp;&nbsp; &nbsp; dl-ssl.google.com <br /> 保存，重新启动SDK Manager.exe<br /> <br /> <br /> 【错误信息】<br /> [2012-04-08 17:42:24 - JavaEye Android Client]  ------------------------------<br /> [2012-04-08 17:42:24 - JavaEye Android Client]  Android Launch!<br /> [2012-04-08 17:42:24 - JavaEye Android Client] The connection  to adb is down, and a severe error has occured.<br /> [2012-04-08 17:42:24 -  JavaEye Android Client] You must restart adb and Eclipse.<br /> [2012-04-08  17:42:24 - JavaEye Android Client] Please ensure that adb  is correctly located  at  'C:\android\android-sdk-windows\platform-tools\adb.exe' and can be   executed.<br /> 原因及解决办法：<br /> 查看任务管理器，关闭所有adb.exe<br /> 重启eclipse即可<br /> <br /> <br /> 【错误信息】<br /> 更新SDK时错误信息：<br /> Site  Authentication<br /> Please login to the following ......<br /> <img id="aimg_iJOFy" alt="" _load="1" src="http://www.51laifu.cn/upload/2012/07/04/20120704155743546.jpg" border="0" width="650" /><br /> 原因及解决办法：<br /> Cancel跳过提示<br /> <br /> <br /> 【错误信息】<br /> 打开Eclipse 提示安装ADT 17<br /> <img id="aimg_CCkAu" alt="" _load="1" src="http://www.51laifu.cn/upload/2012/07/04/20120704155743890.jpg" border="0" /><br /> 原因及解决办法：<br /> 最新的Android SDK只能安装ADT  17.0.0<br /> 可用的下载地址：http://download.csdn.net/detail/merrido/4169460，<br /> 这里可不能用常规方法安装这个  ADT 17.0.0.zip 文件， 首先得解压这个文件，将里面的文件夹覆盖掉Eclipse安装目录下的文件夹。<br /> 然后再用Help-&gt;  install new software-&gt;Add -&gt; Name: ADT&nbsp; &nbsp;Archive:选择ADT 17.0.0.zip  <br /> <br /> <br /> 【错误信息】<br /> 安装ADT 17.0.0时，提示：<br /> Your  original request has been modified.<br /> &nbsp;&nbsp;"Android DDMS" is already installed, so  an update will be performed instead.<br /> &nbsp;&nbsp;"Android Development Tools" is already  installed, so an update will be performed instead.<br /> &nbsp;&nbsp;"Android Hierarchy  Viewer" is already installed, so an update will be performed  instead.<br /> &nbsp;&nbsp;"Android Traceview" is already installed, so an update will be  performed instead.<br /> Cannot complete the install because one or more required  items could not be found.<br /> &nbsp;&nbsp;Software being installed: Android Development  Tools  17.0.0.v201203161636-291853 (com.android.ide.eclipse.adt.feature.group   17.0.0.v201203161636-291853)<br /> &nbsp;&nbsp;Missing requirement: Android Development Tools   17.0.0.v201203161636-291853 (com.android.ide.eclipse.adt.feature.group   17.0.0.v201203161636-291853) requires 'org.eclipse.core.runtime 3.6.0'  but it  could not be found<br /> 原因及解决办法：<br /> <br /> <br /> 【错误信息】<br /> Updates ADT 17.0.0时提示：<br /> Cannot complete the  install because one or more required items could not be found.<br /> &nbsp;&nbsp;Software  being installed: Android Development Tools  17.0.0.v201203161636-291853  (com.android.ide.eclipse.adt.feature.group   17.0.0.v201203161636-291853)<br /> &nbsp;&nbsp;Missing requirement: Android Development Tools   17.0.0.v201203161636-291853 (com.android.ide.eclipse.adt.feature.group   17.0.0.v201203161636-291853) requires 'org.eclipse.core.runtime 3.6.0'  but it  could not be found<br /> 原因及解决办法：<br /> requires  'org.eclipse.core.runtime 3.6.0' but it could not be found<br /> requires  'org.eclipse.ui 3.6.0' but it could not be  found<br /> eclipse需要升级到3.6.0，我的版本是3.5.2<br /> <br /> <br /> 【错误信息】<br /> [2012-04-09 17:14:49 - Info]  ------------------------------<br /> [2012-04-09 17:14:49 - Info] Android  Launch!<br /> [2012-04-09 17:14:49 - Info] Connection with adb was  interrupted.<br /> [2012-04-09 17:14:49 - Info] 0 attempts have been made to  reconnect.<br /> [2012-04-09 17:14:49 - Info] You may want to manually restart adb  from the Devices view.<br /> 原因及解决办法：<br /> 重新启动eclipse<br /> <br /> <br /> 【错误信息】<br /> [2012-04-10 09:45:49 - adb] ADB server didn't  ACK<br /> [2012-04-10 09:45:49 - adb] * failed to start daemon *<br /> 原因及解决办法：<br /> 查看任务管理器,关闭所有adb.exe  <br /> 重启eclipse<br /> <br /> <br /> 【错误信息】<br /> [2012-04-10  09:53:50 - ApiDemos] ------------------------------<br /> [2012-04-10 09:53:50 -  ApiDemos] Android Launch!<br /> [2012-04-10 09:53:50 - ApiDemos] The connection to  adb is down, and a severe error has occured.<br /> [2012-04-10 09:53:50 - ApiDemos]  You must restart adb and Eclipse.<br /> [2012-04-10 09:53:50 - ApiDemos] Please  ensure that adb is correctly  located at  'C:\android\android-sdk-windows\platform-tools\adb.exe' and  can be  executed.<br /> 原因及解决办法：<br /> 重启eclipse<br /> <br /> <br /> 【错误信息】<br /> 安装android sdk时：<br /> -= warning!  =- A folder failed to be renamed or  moved. On Windows this typically means that  a program Is using that  Folder (for example Windows Explorer or your anti-virus  software.)  Please momentarily deactivate your anti-virus software. Please also   close any running programs that may be accessing the directory   'C:\android\android-sdk-windows/android-sdk-windows/too!s'. When ready,  press  YES to try again.<br /> <img id="aimg_CQRRb" alt="" _load="1" src="http://www.51laifu.cn/upload/2012/07/04/20120704155744000.jpg" border="0" width="650" /><br /> 原因及解决办法：<br /> 1, 复制  tools目录<br /> 为一个新的目录 tools-copy ,此时在android-sdk-windows 目录下有两个目录 tools 和  tools-copy<br /> 2, 在tools-copy目录以管理员身份运行 android.bat ，这样就可以正常 update all  了<br /> 3.重新运行SDK Manager.exe.问题解决！<br /> <br /> <br /> 【错误信息】<br /> &#8220;正在启动JavaEyeApiAccessor&#8220;遇到问题。<br /> 不能连接至VM<br /> <img id="aimg_PfXql" alt="" _load="1" src="http://www.51laifu.cn/upload/2012/07/04/20120704155744156.jpg" border="0" /><br /> 原因及解决办法：<br /> 连接不到手机虚拟机<br /> 重启拔插手机连接线<br /> <br /> <br /> 【错误信息】<br /> 调试的时候：<br /> [2012-04-13 17:46:27 -  IpsosAutoAndroid] Failed to install IpsosAutoAndroid.apk on device '?':  timeout<br /> [2012-04-13 17:46:27 - IpsosAutoAndroid] Launch canceled!<br /> 原因及解决办法：<br /> 连接真机调试的时候如果连接太久没响应就会出现timeout<br /> 1.在window-》prensent....-》android-》设置ddms的timeout时间。这种是就最有效、最简洁的。<br /> 2.delete  android里面的 apk，保证速度。不过试过一次后，真机好像变&#8220;聪明了&#8221;，也出现timeout。<br /> 3.Cleaning the project  (Project-&gt;Clean)，不行就重启eclipse或者android，很郁闷的是，重启后运行第一次可以。第二次就开始变慢了，也就是出现timeout<br /> <br /> 4.关闭eclipse  ，然后再重启，就ok<br /> <br /> <br /> 【错误信息】<br /> 调用org.ksoap2.*访问webservice时<br /> 04-13  10:09:49.565: E/dalvikvm(354): Could not find class  'org.ksoap2.serialization.SoapObject', referenced from method......<br /> 04-13  10:09:49.585: E/dalvikvm(354): Could not find class  'org.ksoap2.transport.HttpTransportSE', referenced from method......<br /> 【错误信息】<br /> Unable to open stack trace file  '/data/anr/traces.txt': Permission denied<br /> 原因及解决办法：<br /> Unable to open stack trace file  '/data/anr/traces.txt': Permission  多见于这个Activity你没有在AndroidManifest.xml中注册，就会报这样的错误。<br /> <br /> <br /> 【错误信息】<br /> source not found<br /> 找不到源<br /> 原因及解决办法：<br /> android目录下没有对应的sources文件<br /> <img id="aimg_W4bj9" alt="" _load="1" src="http://www.51laifu.cn/upload/2012/07/04/20120704155744234.jpg" border="0" /><br /> 如下图，不知道为什么，最新的SDK更新API 14/15中有Sources for  Android SDK,而之前的版本的源码就不更新，气愤！<br /> <img id="aimg_PB4z5" alt="" _load="1" src="http://www.51laifu.cn/upload/2012/07/04/20120704155744312.jpg" border="0" /><br /> 下载对应的SDK Sources后，放到\android-sdk-windows\sources  目录下就OK了！<br /> <img id="aimg_HxMJQ" alt="" _load="1" src="http://www.51laifu.cn/upload/2012/07/04/20120704155744453.jpg" border="0" width="650" /><br /> <br /> 【错误信息】<br /> Android使用KSOAP2调用WebService时：<br /> java.lang.NoClassDefFoundError:  org.ksoap2.serialization.SoapObject<br /> 原因及解决办法：<br /> 虽然标明上 Java Build  Path-&gt;Libraries中已经引用了ksoap2-android 包，但是需要order and export中也把该包勾选上<br /> <img id="aimg_GzmWU" alt="" _load="1" src="http://www.51laifu.cn/upload/2012/07/04/20120704155744765.jpg" border="0" width="650" /><br /> <br /> 【错误信息】<br /> <img id="aimg_IQSdq" alt="" _load="1" src="http://www.51laifu.cn/upload/2012/07/04/20120704155744890.jpg" border="0" /><br /> error: Error: No resource found that  matches the given name (at 'layout_toLeftOf' with value'@id/top_send_btn').  <br /> header_questionitemlist.xml /IpsosAutoAndroid/res/layout 第 27 行 Android AAPT  Problem<br /> 原因及解决办法：<br /> <br /> <br /> 【错误信息】<br /> 无法解析导入 com.renren.api.connect.android.R<br /> 原因及解决办法：<br /> 导入android源码有错，R.java文件不能自动生成解决方法<br /> <br /> 【错误信息】<br /> Eclipse中的DDMS无法打开data文件夹下的内容，也不能往里面写东西<br /> 原因及解决办法：<br /> 通过软件获取ROOT权限<br /> <br /> 【错误信息】<br /> Fri May 04 16:27:46 CST 2012<br /> Internal error  logged from JDI Debug: <br /> org.eclipse.jdi.TimeoutException: 等待包 8 时发生超时。<br /> at  org.eclipse.jdi.internal.connect.PacketReceiveManager.getReply(PacketReceiveManager.java:171)<br /> at  org.eclipse.jdi.internal.connect.PacketReceiveManager.getReply(PacketReceiveManager.java:180)<br /> ......<br /> 原因及解决办法：<br /> 重新启动eclipse,不行的话重启机器<br /> <br /> 【错误信息】<br /> java.lang.RuntimeException: Can't create handler  inside thread that has not called Looper.prepare()<br /> 原因及解决办法：<br /> <br /> 如下是有问题的代码： <div align="left">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread t = new Thread()  {@Overridepublic void  run() {super.run();try {QuestionItemlist =  quesHandler.getData();if  (QuestionItemlist.size() == 0)   {Toast.makeText(questionitemlist2.this,"问卷题目为 空",Toast.LENGTH_LONG).show();} else   {Toast.makeText(questionitemlist2.this,"问卷题目已经获 取",Toast.LENGTH_LONG).show();}}  catch (Exception e)  {e.printStackTrace();}}};t.start();</div> <p>【错误信息】<br /> java.lang.IllegalArgumentException: The key must  be an application-specific resource id.<br /> 原因及解决办法：<br /> mRadioButton.setTag(1,sQuestionItem.get(i).getToNext());//设置监听&nbsp;&nbsp;ToNext：下 一题目mRadioButton.setTag(2,sQuestionItem.get(i).getToEnd());//设置监听&nbsp;&nbsp;ToEnd： 是否终止  抛出IllegalArgumentException的原因就在于key不唯一，正确代码如下：<br /> mRadioButton.setTag(R.id.tag_tonext,sQuestionItem.get(i).getToNext());// 设置监听&nbsp;&nbsp;ToNext：下一题目 mRadioButton.setTag(R.id.tag_toend,sQuestionItem.get(i).getToEnd());//设置 监听&nbsp;&nbsp;ToEnd：是否终止  <br /> 【错误信息】<br /> 点击Debug 运行 结果模拟器总是会弹出Waiting for  Debugger 然后程序又可以正常运行<br /> 如果你想调试的时候去掉 Waiting for Debugger 提示<br /> 原因及解决办法：<br /> 重启启动机器就OK</p><p>本文出自 &#8220;<a href="http://2402766.blog.51cto.com">java之路</a>&#8221; 博客，请务必保留此出处<a href="http://2402766.blog.51cto.com/2392766/1102373">http://2402766.blog.51cto.com/2392766/1102373</a></p>     		</div></div><img src ="http://www.blogjava.net/yxj1314520/aggbug/399423.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yxj1314520/" target="_blank">姚先进</a> 2013-05-17 16:57 <a href="http://www.blogjava.net/yxj1314520/archive/2013/05/17/399423.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Fedora12下搭建Qt Creator的ARM开发环境 并 移植Qt4.6.2到</title><link>http://www.blogjava.net/yxj1314520/archive/2013/05/13/399215.html</link><dc:creator>姚先进</dc:creator><author>姚先进</author><pubDate>Mon, 13 May 2013 08:19:00 GMT</pubDate><guid>http://www.blogjava.net/yxj1314520/archive/2013/05/13/399215.html</guid><wfw:comment>http://www.blogjava.net/yxj1314520/comments/399215.html</wfw:comment><comments>http://www.blogjava.net/yxj1314520/archive/2013/05/13/399215.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yxj1314520/comments/commentRss/399215.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yxj1314520/services/trackbacks/399215.html</trackback:ping><description><![CDATA[<div><h1>Fedora12下搭建Qt Creator的ARM开发环境 并 移植Qt4.6.2到Micro2440（一）</h1> 		 		 		<div> 			 			<div id="ads_r_tpc" style="clear:right;margin:0 0 8px 8px;"><a href="http://www.arm9home.net/read.php?tid-17639.html" target="_blank"><img src="http://www.arm9home.net/ac/play/210-android.jpg"  alt="" /></a></div> 			<div id="mag_tpc" style="margin-bottom:1em;"> 				<blockquote><div><span f12=""  fn"="">管理提醒： 				</span>本帖被 kasim 执行置顶操作(2010-04-11) 				</div> 				</blockquote> 			</div> 		<div id="read_tpc"><div align="left">Fedora12下搭建Qt Creator的ARM开发环境 并 移植Qt4.6.2到Micro2440（一）</div><div align="left"></div><div align="left">参考：</div><div align="left"><a href="http://hi.baidu.com/jiyeqian/blog/item/f46d26a2ff3f7da6caefd0d6.html" target="_blank" id="url_1"><span style="color:#0000ff ">http://hi.baidu.com/jiyeqian/blog/item/f46d26a2ff3f7da6caefd0d6.html</span></a></div><div align="left"><a href="http://blog.csdn.net/dongliqiang2006/archive/2009/08/30/4500002.aspx" target="_blank" id="url_2"><span style="color:#0000ff ">http://blog.csdn.net/dongliqiang2006/archive/2009/08/30/4500002.aspx</span></a></div><div align="left"></div><div align="left">环境：虚拟机Fedora12（建议安装Vmware Tools，详细安装方法参照Vmware帮助文档），USB串口，minicom终端。（minicom经常打不开ttyUSB0设备，我的解决方法是，打不开时就将USB串口移除，运行minicom，然后再接上USB串口，此时运行minicom一般都能打开设备）</div><div align="left"></div><div align="left">软件准备：</div><div align="left">到http://qt.nokia.com/downloads-cn下载最新版的软件包，当前是：</div><div align="left"></div><div align="left">用于 Linux/X11 32位 的 Qt Creator 1.3.1 二进制软件包qt-creator-linux-x86-opensource-1.3.1.bin（http://qt.nokia.com/downloads/qt-creator-binary-for-linux-x11-32-bit）</div><div align="left"></div><div align="left">用于嵌入式 Linux 的 Qt 库 4.6.2包qt-everywhere-opensource-src-4.6.2.tar.gz（http://qt.nokia.com/downloads/embedded-linux-cpp）</div><div align="left"></div><div align="left">到http://hi.baidu.com/jiyeqian/blog/item/f46d26a2ff3f7da6caefd0d6.html下载arm920t-eabi.tgz（即arm-linux-gcc-4.1.2）（http://qtextended.org/downloads/toolchains/arm920t-eabi.tgz）</div><div align="left"></div><div align="left">到http://www.arm9.net/download.asp下载Root_Qtopia，我用的是友善光盘里的root_qtopia-20100108.tar.gz（http://www.arm123.com.cn/linux/root_qtopia-20100108.tar.gz）</div><div align="left"></div><div align="left">下载tslib1.4，这个忘了在哪下载的了，网上有很多，有些不能用，大家自己找个能用的吧。</div><div align="left"></div><div align="left">*以下安装方法主要来自文章<a href="http://hi.baidu.com/jiyeqian/blog/item/f46d26a2ff3f7da6caefd0d6.html" target="_blank" id="url_3"><span style="color:#0000ff ">http://hi.baidu.com/jiyeqian/blog/item/f46d26a2ff3f7da6caefd0d6.html</span></a></div><div align="left"></div><div align="left">将 qt-everywhere-opensource-src-4.6.2.tar.gz 压缩包解压为3份，分别编译 PC ，嵌入式 x86 和 arm 三个版本。</div><div align="left"></div><div align="left">我在root目录下建立tmp文件夹，将qt-everywhere-opensource-src-4.6.2.tar.gz直接解压后复制2分，分别命名为pc、x86、arm。</div><div align="left"></div><div align="left"></div><div align="left">1. 编译 PC 版：</div><div align="left">进入pc目录</div><div align="left">#./configure</div><div align="left"># gmake</div><div align="left"># gmake install</div><div align="left">安装过程比较长，没有碰到过错误。</div><div align="left"></div><div align="left">2. 编译嵌入式x86版：</div><div align="left">进入x86目录</div><div align="left"># ./configure -embedded x86 -qt-gfx-qvfb -qt-kbd-qvfb -qt-mouse-qvfb</div><div align="left"># gmake</div><div align="left"># gmake install</div><div align="left">安装过程比较长，没有碰到过错误。</div><div align="left"></div><div align="left">编译安装PC版中的 qvfb：</div><div align="left">进入pc/tools/qvfb/目录</div><div align="left">#make</div><div align="left">编译完毕，将pc/bin目录下的qvfb文件复制到/usr/local/Trolltech/QtEmbedded-4.6.2/bin目录。</div><div align="left"></div><div align="left">3. 编译嵌入式arm版（需要 arm-linux-gcc 的支持）：</div><div align="left">使用友善自带的ARM-Linux GCC 4.3.2编译完了，程序移植到开发板上后，出现Segmentation Fault错误，按原文，使用4.1.2正常。</div><div align="left"></div><div align="left">直接将arm920t-eabi.tgz解压缩到根目录，不可以像文章中说的那样&#8220;我把它放在：/usr/local/arm/4.1.2/ &#8221;，最起码我放过去后出错了。</div><div align="left">把编译器路径加入系统环境变量，运行命令： </div><div align="left">#gedit /root/.bashrc </div><div align="left">编辑/root/.bashrc文件，在最后一行加上 export PATH=/opt/toolchains/arm920t-eabi/bin:$PATH</div><br /><div align="left"></div><div align="left">编译tslib对触摸屏支持：</div><div align="left">下载，tslib1.4.tar.gz，解压后：</div><div align="left"># ./configure --prefix=/usr/local/tslib/ --host=arm-linux ac_cv_func_malloc_0_nonnull=yes</div><div align="left"># make </div><div align="left"># make install</div><div align="left">我下载的包解压后没有configure文件，需要运行autogen.sh后才能生成。</div><div align="left"></div><div align="left"><strike><span style="color:#0000ff ">设置环境变量，以便编译时找到相关的库：</span></strike></div><div align="left"><strike><span style="color:#0000ff ">#  export  CPLUS_INCLUDE_PATH=/opt/toolchains/arm920t-eabi/arm-angstrom-linux-gnueabi/include/c++:/opt/toolchains/arm920t-eabi/arm-angstrom-linux-gnueabi/include/c++/arm-none-linux-gnueabi</span></strike></div><div align="left"><strike><span style="color:#0000ff "># export PATH=/opt/toolchains/arm920t-eabi/bin:$PATH</span></strike></div><div align="left"><strike> </strike><strike> </strike><strike><span style="color:#0000ff "><br /></span></strike></div><div align="left"><strike><span style="color:#0000ff ">修改</span></strike><strike><span style="color:#0000ff ">qt-everywhere-opensource-src-4.6.2/mkspecs/qws/linux-arm-g++/qmake.conf </span></strike><strike><span style="color:#0000ff ">文件（添加</span></strike><strike><span style="color:#0000ff ">lts</span></strike><strike><span style="color:#0000ff ">参数）：</span></strike></div><div align="left"><strike><span style="color:#0000ff ">QMAKE_CC&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = arm-linux-gcc -lts</span></strike></div><div align="left"><strike><span style="color:#0000ff ">QMAKE_CXX&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = arm-linux-g++ -lts</span></strike></div><div align="left"><strike><span style="color:#0000ff ">QMAKE_LINK&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = arm-linux-g++ -lts</span></strike></div><div align="left"><strike><span style="color:#0000ff ">QMAKE_LINK_SHLIB&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = arm-linux-g++ -lts</span></strike></div><div align="left"><strike><span style="color:#0000ff ">这一步必须有，不然肯定出错。</span></strike></div><div align="left"></div><div align="left">配置：</div><div align="left">必须加上&#8220;<span style="color:#ff6600 ">-prefix /usr/local/Trolltech/QtEmbedded-4.6.2-arm </span>&#8221;参数， 不然安装后不在QtEmbedded-4.6.2-arm文件夹下，而是覆盖了QtEmbedded-4.6.2。</div><div align="left"># ./configure \</div><div align="left"><span style="color:#ff6600 ">-prefix /usr/local/Trolltech/QtEmbedded-4.6.2-arm \ <br /></span></div><div align="left">-opensource \</div><div align="left">-confirm-license \</div><div align="left">-release -shared \</div><div align="left">-embedded arm \</div><div align="left">-xplatform qws/linux-arm-g++ \</div><div align="left">-depths 16,18,24 \</div><div align="left">-fast \</div><div align="left">-optimized-qmake \</div><div align="left">-pch \</div><div align="left">-qt-sql-sqlite \</div><div align="left">-qt-libjpeg \</div><div align="left">-qt-zlib \</div><div align="left">-qt-libpng \</div><div align="left">-qt-freetype \</div><div align="left">-little-endian -host-little-endian \</div><div align="left">-no-qt3support \</div><div align="left">-no-libtiff -no-libmng \</div><div align="left">-no-opengl \</div><div align="left">-no-mmx -no-sse -no-sse2 \</div><div align="left">-no-3dnow \</div><div align="left">-no-openssl \</div><div align="left">-no-webkit \</div><div align="left">-no-qvfb \</div><div align="left">-no-phonon \</div><div align="left">-no-nis \</div><div align="left">-no-opengl \</div><div align="left">-no-cups \</div><div align="left">-no-glib \</div><div align="left">-no-xcursor -no-xfixes -no-xrandr -no-xrender \</div><div align="left">-no-separate-debug-info \</div><div align="left">-nomake examples -nomake tools -nomake docs \</div><div align="left">-qt-mouse-tslib <span style="color:#0000ff "><strike>-I/usr/local/tslib/include -L/usr/local/tslib/lib</strike></span></div><div align="left"><span style="color:#0000ff "><strike><br /></strike></span></div><div align="left"><span style="color:#ff0000 ">上面划掉的蓝色内容，可以不要的，这样编辑也不会出错（虚拟机搞坏了，不得已重装，配置参数时忘了干上面的工作了，结果发现没出错）。</span><span style="color:#0000ff "><strike><br /></strike></span></div><div align="left"><span style="color:#ff0000 "><br /></span></div><div align="left"><span style="color:#ff0000 ">关于配置参数，参照一下这篇文章吧，可以用configure -embedded &#8211;help查看。<br /></span></div><div align="left"><span style="color:#0000ff "><strike><br /></strike></span></div><div align="left"><span style="color:#0000ff ">http://www.cuteqt.com/blog/?p=582</span><span style="color:#0000ff "><strike><br /></strike></span></div><div align="left"></div><div align="left">如果你放弃配置，则使用命令：# gmake confclean</div><div align="left"></div><div align="left">编译：# gmake</div><div align="left"></div><div align="left">安装：# gmake install </div><div align="left"></div><div align="left">安装完成后，在 /usr/local/Trolltech 目录中有三个文件夹：Qt-4.6.2、QtEmbedded-4.6.2、QtEmbedded-4.6.2-arm。</div><div align="left"></div><div align="left">4、移植</div><div align="left">我是通过NFS启动的系统，具体操作可以参照友善的手册，在http://www.arm9.net/download.asp有下载，在第5.5.3节通过NFS启动系统。</div><div align="left"></div><div align="left">将Fedora12上&nbsp; /usr/local/Trolltech/QtEmbedded-4.6.2-arm/lib 中的所有文件复制到/opt/FriendlyARM/mini2440/root_qtopia/usr/local/Trolltech/QtEmbedded-4.6.2-arm/lib目录中（对应目录复制，相当于复制到了开发板对应目录中），其实需要的时候可以裁剪，看原文吧。</div><div align="left"></div><div align="left">将Fedora12上&nbsp; /usr/local/tslib 中的库复制到/opt/FriendlyARM/mini2440/root_qtopia/usr/local中。即将/usr/local/tslib下的所有文件复制到/opt/FriendlyARM/mini2440/root_qtopia/usr/local文件夹下。</div><div align="left"></div><div align="left">如果运行时还缺少其他的库，复制方法相同。也可以使用arm-angstrom-linux-gnueabi-readelf -a 程序名 | grep "Share"，命令查看需要哪些共享库，一起复制过去。</div><div align="left"></div><div align="left">为支持触摸屏，开机自动设置环境变量，在2440的 /etc/profile中追加：</div><div align="left">export LD_LIBRARY_PATH=/usr/local/lib:$QTDIR/lib:$LD_LIBRARY_PATH&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div align="left">export TSLIB_ROOT=/usr/local/lib&nbsp;&nbsp;&nbsp;&nbsp; </div><div align="left">export TSLIB_TSDEVICE=/dev/input/event0</div><div align="left">export TSLIB_FBDEVICE=/dev/fb0&nbsp; </div><div align="left">export TSLIB_PLUGINDIR=/usr/local/lib/ts</div><div align="left">export TSLIB_CONSOLEDEVICE=none</div><div align="left">export TSLIB_CONFFILE=/usr/local/etc/ts.conf</div><div align="left">export POINTERCAL_FILE=/etc/pointercal</div><div align="left">export TSLIB_CALIBFILE=/etc/pointercal</div><div align="left">export QWS_MOUSE_PROTO=Tslib:/dev/input/event0</div><div align="left"></div><div align="left">取消/usr/local/etc/ts.conf中的第一个注释：</div><div align="left"># module_raw input （去掉#，并且该行顶格）</div><div align="left">我编辑时没有&#8220;#&#8221;</div><div align="left"></div><div align="left">启动Micro2440运行 /usr/local/bin/ts_calibrate 校正触摸屏。</div><div align="left"></div><div align="left">到此Qt4.6.2的移植暂告一段落，移植还没有完，此时如果在开发板上运行Qt4.6.2-arm编译的程序，则会出现&#8220;relocation  error: /usr/local/Trolltech/QtEmbedded-4.6.2-arm/lib/libQtGui.so.4:  symbol powf, version GLIBCXX_3.4 not defined in file libstdc++.so.6 with  link time reference&#8221;错误。</div><div align="left"></div><div align="left">今天晚了，明天继续奉上&#8230;&#8230;</div><div align="left"><span id="att_1004"><img src="http://www.arm9home.net/images/wind/file/zip.gif" align="absmiddle"  alt="" /><a href="http://www.arm9home.net/job.php?action-download-pid-tpc-tid-5161-aid-1004.html" target="_blank"> tslib-1.4.part1.rar</a> (900 K) 下载次数:1066 </span><span id="att_1005"><img src="http://www.arm9home.net/images/wind/file/zip.gif" align="absmiddle"  alt="" /><a href="http://www.arm9home.net/job.php?action-download-pid-tpc-tid-5161-aid-1005.html" target="_blank"> tslib-1.4.part2.rar</a> (223 K) 下载次数:936 </span></div></div></div></div><br /><br /><div><div fl"="" style="margin-left:1em;"> 			<h1>&nbsp;Fedora12下搭建Qt Creator的ARM开发环境 并 移植Qt4.6.2到Micro2440（二）</h1> 		</div> 		 		 			 			<div id="ads_r_tpc" style="clear:right;margin:0 0 8px 8px;"><a href="http://www.arm9home.net/read.php?tid-17639.html" target="_blank"><img src="http://www.arm9home.net/ac/play/210-android.jpg"  alt="" /></a></div> 			<div id="mag_tpc" style="margin-bottom:1em;"> 				<blockquote><div><span f12=""  fn"="">管理提醒： 				</span>本帖被 kasim 执行加亮操作(2010-04-11) 				</div> 				</blockquote> 			</div> 		<div align="left">Fedora12下搭建Qt Creator的ARM开发环境 并 移植Qt4.6.2到Micro2440（二）</div><div align="left"></div><div align="left">继续&#8230;&#8230;</div><div align="left"></div><div align="left">5、安装Qt-creator-1.3.1</div><div align="left">把下载的qt-creator-linux-x86-opensource-1.3.1.bin文件拷到一个目录（如前面的/root/tmp目录），进入目录：</div><div align="left"></div><div align="left">设置qt-creator-linux-x86-opensource-1.3.1.bin文件为可执行</div><div align="left">#chmod +x qt-creator-linux-x86-opensource-1.3.1.bin</div><div align="left"></div><div align="left">安装：</div><div align="left"># ./ qt-creator-linux-x86-opensource-1.3.1.bin</div><div align="left"></div><div align="left">启动安装界面，默认一路Next即可。</div><div align="left"></div><div align="left">*如果我们下载的是Qt的SDK（qt-sdk-linux-x86-opensource-2010.02.bin），这里可以选择安装Qt的开发环境，这样，在前面安装pc版Qt那步就可以省了，关键是可以省出很多时间的。</div><div align="left"></div><div align="left">6、Qt-creator开发环境的配置</div><div align="left">启动Qt-creator。</div><div align="left"></div><div align="left">在Qt-creator菜单栏Tools&#8212;〉Options&#8230;打开Options窗口。</div><div align="left">在Options界面左侧，点击Qt4&#8212;〉Qt Versions右侧显示Qt Versions设置界面。</div><div align="left"></div><div align="left">在Qt Versions界面中点击那个蓝色的大&#8220;<span style="color:#365f91 ">&#9547;</span>&#8221;号图标</div><div align="left">在下方Version Name：文本框内输入Qt的版本名，可以随便填，能区分各个版本即可（如pc版取Qt4.6.2-pc、x86版取QtE4.6.2-x86、arm版取QtE4.6.2-arm）。</div><div align="left"></div><div align="left">单击Qmake Location：右侧Browse&#8230;按钮，在弹出的&#8220;Select QMake Executable&#8221;窗口中找到对应版本的qmake程序（按照我们前面安转的，pc版路径：/usr/local/Trolltech/Qt-4.6.2/bin/qmake，x86版路径：/usr/local/Trolltech/QtEmbedded-4.6.2/bin/qmake，arm版路径：/usr/local/Trolltech/QtEmbedded-4.6.2-arm/bin/qmake），单击打开，回到Qt Versions界面。</div><div align="left"></div><div align="left">回到Qt Versions界面，单击Debugging Helper：右侧Rebuild按钮，等待片刻，看到Debugging Helper：后出现一个绿色的&#8220;<span style="color:#00b050 ">&#8730;</span>&#8221;即可。</div><div align="left"></div><div align="left">同理完成其他版本的添加。</div><div align="left"></div><div align="left">添加完毕，单击OK按钮关闭Options窗口。</div><div align="left"></div><div align="left">到此，Qt-creator配置完毕（我暂时就配置了这些）。</div><div align="left"></div><div align="left">7、一个例子</div><div align="left">从usr/local/Trolltech/QtEmbedded-4.6.2/demos下复制books例程到root/tmp文件夹下。</div><div align="left"></div><div align="left">启动Qt-creator，File&#8212;〉Open File or Project&#8230;，打开root/tmp/books/books.pro。</div><div align="left"></div><div align="left">这里我们分两部分，首先编译x86下的，并运行在qvfb下，再编译arm下的，移到开发板下运行。</div><div align="left"></div><div align="left">7.1、x86下的编译与调试</div><div align="left">在Qt-creator界面左侧点击Projects图标，打开工程设置界面。</div><div align="left"></div><div align="left">从上往下，</div><div align="left"></div><div align="left">在Edit Project Settings for Project books&#8212;&#8212;〉Build Settings&#8212;&#8212;〉Edit Build Configuration：单击Add，在下拉列表中选择Using Qt Version &#8220;QtE4.6.2-x86&#8221;弹出对话框单击Ok按钮，在Edit Build Configuration：下会出现蓝色的Make QtE4.6.3-x86 Release active.字符，单击激活QtE4.6.3-x86 Release。</div><div align="left"></div><div align="left">在Run Settings&#8212;&#8212;〉Edit run configuration：右侧单击Show Details按钮，在打开的下拉列表中Arguments：文本框中添加参数&#8220;-qws&#8221;。</div><div align="left"></div><div align="left">设置完毕，点击Edit图标，回到编辑界面。</div><div align="left"></div><div align="left">编译：在Build菜单下，先Clean Project &#8220;books&#8221;，然后Build Project &#8220;books&#8221;，在右下角Compile Output窗口能看到编译信息（按我们上面这样走来，到此编译不会出问题的）。</div><div align="left"></div><div align="left">运行：</div><div align="left"> 启动终端，# /usr/local/Trolltech/QtEmbedded-4.6.2/bin/qvfb -width 800 -height 480 &amp;，启动Qvfb。</div><div align="left"> 回到Qt-creator，Build&#8212;&#8212;〉Run，运行程序。</div><div align="left"></div><div align="left">切换我们的Qvfb窗口中，是不是看到Books运行的界面了。</div><div align="left"></div><div align="left">调试：Debug&#8212;&#8212;〉Start Debugging&#8212;&#8212;〉Start Debugging，即可启动调试（请保证books路径中没有中文名，即不要把books工程放在了某个含有中文字符的文件夹下，不然无法启动调试）。</div><div align="left"></div><div align="left">此时感觉如果前面编译选项Edit Project Settings for Project books&#8212;&#8212;〉Build Settings&#8212;&#8212;〉Edit Build Configuration：选择Debug项，则调试启动速度比Release时的要快很多。</div><div align="left"></div><div align="left">7.2、arm编译并移植</div><div align="left"></div><div align="left">编译：在Projects设置界面下，选择Using Qt Version &#8220;QtE4.6.2-arm&#8221;项，余下参数不变，build。</div><div align="left"></div><div align="left">复制编译好的文件（也许还有images文件夹）到2440的NFS文件系统的某个目录下，我直接把books文件夹复制过去了（在Fedora12 文件系统下是/opt/FriendlyARM/mini2440/root_qtopia/home/plg文件夹下）。</div><div align="left"></div><div align="left">运行及错误处理：</div><div align="left">在minicom下面，ps一下，找到qpe进程对应的PID，比如1234，然后通过kill 1234杀死Qtopia。</div><div align="left">进入books目录，执行./books &#8211;qws，此时就会出现前面讲到的&#8220;relocation  error: /usr/local/Trolltech/QtEmbedded-4.6.2-arm/lib/libQtGui.so.4:  symbol powf, version GLIBCXX_3.4 not defined in file libstdc++.so.6 with  link time reference&#8221;错误。</div><div align="left"></div><div align="left">我的解决办法是进入主机/opt/toolchains/arm920t-eabi/arm-angstrom-linux-gnueabi/lib目录下找到libstdc++.so.6链接的文件libstdc++.so.6.0.8（通过右键属性&#8212;&#8212;〉基本，可以看到链接的文件），复制并重命名为libstdc++.so.6到/opt/FriendlyARM/mini2440/root_qtopia/lib文件夹下，之前别忘了将该文件夹下的libstdc++.so.6移到其它地方或重命名，如libstdc++.so.6.old。</div><div align="left"></div><div align="left">*重命名其实是比较野蛮的方法，可以用ln命令的，参照下面这篇文章&#8230;&#8230;</div><div align="left"></div><div align="left">http://hi.baidu.com/a263238386/blog/item/362f01ce7b11a10a93457eae.html</div><div align="left"></div><div align="left">然后再运行./books &#8211;qws，看问题是不是解决了！</div><div align="left"></div><div align="left">这里有个新的问题还没解决，就是在开发版上运行时字非常小，留着以后处理吧。</div><div align="left"></div><div align="left">OK！至此，Fedora12下搭建Qt Creator的ARM开发环境 并 移植Qt4.6.2到Micro2440算告一段落了，留下两个问题：字体非常小的问题、开发板上的远程调试，留待下次解决。</div></div><img src ="http://www.blogjava.net/yxj1314520/aggbug/399215.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yxj1314520/" target="_blank">姚先进</a> 2013-05-13 16:19 <a href="http://www.blogjava.net/yxj1314520/archive/2013/05/13/399215.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>追求</title><link>http://www.blogjava.net/yxj1314520/archive/2013/05/10/399088.html</link><dc:creator>姚先进</dc:creator><author>姚先进</author><pubDate>Fri, 10 May 2013 02:02:00 GMT</pubDate><guid>http://www.blogjava.net/yxj1314520/archive/2013/05/10/399088.html</guid><wfw:comment>http://www.blogjava.net/yxj1314520/comments/399088.html</wfw:comment><comments>http://www.blogjava.net/yxj1314520/archive/2013/05/10/399088.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yxj1314520/comments/commentRss/399088.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yxj1314520/services/trackbacks/399088.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp; 像风一样沐浴自由，等待木棉花开<br /><br />离别多时，猛然看到他的文字，迎面而来的是清新和洒脱，放飞了自己，开阔了心境。从心里面为他高兴，又隐隐的疼惜自己，因为一个人还没有放下。<br />多伤感，多惆怅，多很多的是逃避。<br /><br />有时候突然豪言壮语，突然壮志凌云，突然觉得一切都可能。但是有时又发现那些东西可有可无，无非是名利，是物质满足，是填补欲望，<br />没有真正的追求<br /><img src ="http://www.blogjava.net/yxj1314520/aggbug/399088.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yxj1314520/" target="_blank">姚先进</a> 2013-05-10 10:02 <a href="http://www.blogjava.net/yxj1314520/archive/2013/05/10/399088.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>json 解析</title><link>http://www.blogjava.net/yxj1314520/archive/2013/04/22/398231.html</link><dc:creator>姚先进</dc:creator><author>姚先进</author><pubDate>Mon, 22 Apr 2013 12:21:00 GMT</pubDate><guid>http://www.blogjava.net/yxj1314520/archive/2013/04/22/398231.html</guid><wfw:comment>http://www.blogjava.net/yxj1314520/comments/398231.html</wfw:comment><comments>http://www.blogjava.net/yxj1314520/archive/2013/04/22/398231.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yxj1314520/comments/commentRss/398231.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yxj1314520/services/trackbacks/398231.html</trackback:ping><description><![CDATA[<div>&nbsp; package com.example.hoteltest;<br />&nbsp;&nbsp; &nbsp;import java.io.ByteArrayOutputStream; &nbsp;<br />import java.io.InputStream; &nbsp;<br />import java.net.*; &nbsp;<br />import java.util.ArrayList; &nbsp;<br />import java.util.HashMap; &nbsp;<br />import java.util.List; &nbsp;<br />import java.util.Map; &nbsp;<br />import org.json.JSONArray; &nbsp;<br />import org.json.JSONObject; &nbsp;<br />import android.util.Log; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; public class JSON { &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /** <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 获取"数组形式"的JSON数据， <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 数据形式：[{"id":1,"name":"小猪"},{"id":2,"name":"小猫"}] <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @param path&nbsp; 网页路径 <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @return&nbsp; 返回List <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @throws Exception <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */ &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static List&lt;Map&lt;String, String&gt;&gt; getJSONArray(String path) throws Exception { &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String json = null; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List&lt;Map&lt;String, String&gt;&gt; list = new ArrayList&lt;Map&lt;String, String&gt;&gt;(); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Map&lt;String, String&gt; map = null; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; URL url = new URL(path); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpURLConnection conn = (HttpURLConnection) url.openConnection();// 利用HttpURLConnection对象,我们可以从网络中获取网页数据. &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.setConnectTimeout(5 * 1000);&nbsp;&nbsp; // 单位是毫秒，设置超时时间为5秒 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.setRequestMethod("GET");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // HttpURLConnection是通过HTTP协议请求path路径的，所以需要设置请求方式,可以不设置，因为默认为GET &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (conn.getResponseCode() == 200) {// 判断请求码是否是200码，否则失败 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InputStream is = conn.getInputStream(); // 获取输入流 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; byte[] data = readStream(is);&nbsp;&nbsp; // 把输入流转换成字符数组 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; json = new String(data);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 把字符数组转换成字符串 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //数据形式：[{"id":1,"name":"小猪","age":22},{"id":2,"name":"小猫","age":23}] &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JSONArray jsonArray = new JSONArray(json); //数据直接为一个数组形式，所以可以直接 用android提供的框架JSONArray读取JSON数据，转换成Array &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; jsonArray.length(); i++) { &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JSONObject item = jsonArray.getJSONObject(i); //每条记录又由几个Object对象组成 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int id = item.getInt("id");&nbsp;&nbsp;&nbsp;&nbsp; // 获取对象对应的值 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String name = item.getString("name"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map = new HashMap&lt;String, String&gt;(); // 存放到MAP里面 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map.put("id", id + ""); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map.put("name", name); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(map); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ***********测试数据****************** &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (Map&lt;String, String&gt; list2 : list) { &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String id = list2.get("id"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String name = list2.get("name"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Log.i("abc", "id:" + id + " | name:" + name); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return list; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /** <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 获取"对象形式"的JSON数据， <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 数据形式：{"total":2,"success":true,"arrayData":[{"id":1,"name":"小猪"},{"id":2,"name":"小猫"}]} <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @param path&nbsp; 网页路径 <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @return&nbsp; 返回List <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @throws Exception <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */ &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static List&lt;Map&lt;String, String&gt;&gt; getJSONObject(String path) throws Exception { &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List&lt;Map&lt;String, String&gt;&gt; list = new ArrayList&lt;Map&lt;String, String&gt;&gt;(); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Map&lt;String, String&gt; map = null; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; URL url = new URL(path); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpURLConnection conn = (HttpURLConnection) url.openConnection();// 利用HttpURLConnection对象,我们可以从网络中获取网页数据. &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.setConnectTimeout(5 * 1000);&nbsp;&nbsp; // 单位是毫秒，设置超时时间为5秒 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.setRequestMethod("GET");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // HttpURLConnection是通过HTTP协议请求path路径的，所以需要设置请求方式,可以不设置，因为默认为GET &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (conn.getResponseCode() == 200) {// 判断请求码是否是200码，否则失败 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InputStream is = conn.getInputStream(); // 获取输入流 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; byte[] data = readStream(is);&nbsp;&nbsp; // 把输入流转换成字符数组 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String json = new String(data); // 把字符数组转换成字符串 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //数据形式：{"total":2,"success":true,"arrayData":[{"id":1,"name":"小猪"},{"id":2,"name":"小猫"}]} &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JSONObject jsonObject=new JSONObject(json);&nbsp;&nbsp;&nbsp;&nbsp; //返回的数据形式是一个Object类型，所以可以直接转换成一个Object &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int page=jsonObject.getInt("page"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String type=jsonObject.getString("type"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Log.i("abc", "type:" + type + " |page:" + page);&nbsp;&nbsp; //测试数据 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JSONArray jsonArray = jsonObject.getJSONArray("hotels");//里面有一个数组数据，可以用getJSONArray获取数组 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; jsonArray.length(); i++) { &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JSONObject item = jsonArray.getJSONObject(i); // 得到每个对象<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double distance=item.getDouble("distance");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String direction=item.getString("direction");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int star_rating=item.getInt("star_rating");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String name=item.getString("name");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double nightly_rate=item.getDouble("nightly_rate");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double promoted_nightly_rate=item.getDouble("promoted_nightly_rate");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double total_rate=item.getDouble("total_rate");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double longitude=item.getDouble("longitude");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String key=item.getString("key");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double promoted_total_rate=item.getDouble("promoted_total_rate");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String latitude=item.getString("latitude");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long master_id=item.getLong("master_id");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String thumbnail=item.getString("thumbnail");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String street_address=item.getString("street_address");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double review_score=item.getDouble("review_score");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map = new HashMap&lt;String, String&gt;(); // 存放到MAP里面 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map.put("distance", distance + ""); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map.put("direction", direction + ""); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map.put("star_rating", star_rating + ""); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map.put("name", name + ""); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map.put("nightly_rate", nightly_rate + ""); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map.put("promoted_nightly_rate", promoted_nightly_rate + ""); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map.put("total_rate", total_rate + ""); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map.put("key", key + ""); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map.put("promoted_total_rate", promoted_total_rate + ""); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map.put("latitude", latitude + ""); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map.put("master_id", master_id + ""); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map.put("thumbnail", thumbnail + "");&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map.put("street_address", street_address + ""); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map.put("review_score", review_score + ""); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(map); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ***********测试数据****************** &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (Map&lt;String, String&gt; list2 : list) { &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String distance = list2.get("distance"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String direction = list2.get("direction"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String star_rating = list2.get("star_rating"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String name = list2.get("name"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String nightly_rate = list2.get("nightly_rate"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String promoted_nightly_rate = list2.get("promoted_nightly_rate"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String total_rate = list2.get("total_rate"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String key = list2.get("key"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String promoted_total_rate = list2.get("promoted_total_rate"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String latitude = list2.get("latitude"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String master_id = list2.get("master_id"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String thumbnail = list2.get("thumbnail"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String street_address = list2.get("street_address"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String review_score = list2.get("review_score"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(distance);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(direction);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(star_rating);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(name);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(nightly_rate);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(promoted_nightly_rate);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(total_rate);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(key);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(promoted_total_rate);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(latitude);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(master_id);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(thumbnail);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(street_address);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(review_score);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return list; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /** <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 获取类型复杂的JSON数据 <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *数据形式： <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {"name":"小猪", <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "age":23, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "content":{"questionsTotal":2, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "questions": [ { "question": "what's your name?", "answer": "小猪"},{"question": "what's your age", "answer": "23"}] <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @param path&nbsp; 网页路径 <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @return&nbsp; 返回List <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @throws Exception <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */ &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static List&lt;Map&lt;String, String&gt;&gt; getJSON(String path) throws Exception { &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List&lt;Map&lt;String, String&gt;&gt; list = new ArrayList&lt;Map&lt;String, String&gt;&gt;(); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Map&lt;String, String&gt; map = null; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; URL url = new URL(path); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpURLConnection conn = (HttpURLConnection) url.openConnection();// 利用HttpURLConnection对象,我们可以从网络中获取网页数据. &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.setConnectTimeout(5 * 1000);&nbsp;&nbsp; // 单位是毫秒，设置超时时间为5秒 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.setRequestMethod("GET");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // HttpURLConnection是通过HTTP协议请求path路径的，所以需要设置请求方式,可以不设置，因为默认为GET &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (conn.getResponseCode() == 200) {// 判断请求码是否是200码，否则失败 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InputStream is = conn.getInputStream(); // 获取输入流 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; byte[] data = readStream(is);&nbsp;&nbsp; // 把输入流转换成字符数组 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String json = new String(data); // 把字符数组转换成字符串 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*数据形式： <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {"name":"小猪", <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "age":23, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "content":{"questionsTotal":2, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "questions": [ { "question": "what's your name?", "answer": "小猪"},{"question": "what's your age", "answer": "23"}] <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JSONObject jsonObject=new JSONObject(json);&nbsp;&nbsp;&nbsp;&nbsp; //返回的数据形式是一个Object类型，所以可以直接转换成一个Object &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String name=jsonObject.getString("name");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int age=jsonObject.getInt("age"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Log.i("abc", "name:" + name + " | age:" + age); //测试数据 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JSONObject contentObject=jsonObject.getJSONObject("content");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //获取对象中的对象 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String questionsTotal=contentObject.getString("questionsTotal");&nbsp;&nbsp;&nbsp; //获取对象中的一个值 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Log.i("abc", "questionsTotal:" + questionsTotal);&nbsp;&nbsp; //测试数据 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JSONArray contentArray=contentObject.getJSONArray("questions");&nbsp;&nbsp;&nbsp;&nbsp; //获取对象中的数组 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; contentArray.length(); i++) { &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JSONObject item = contentArray.getJSONObject(i); // 得到每个对象 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String question = item.getString("question");&nbsp;&nbsp; // 获取对象对应的值 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String answer = item.getString("answer"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map = new HashMap&lt;String, String&gt;(); // 存放到MAP里面 &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map.put("question", question); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map.put("answer", answer); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(map); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ***********测试数据****************** &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (Map&lt;String, String&gt; list2 : list) { &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String question = list2.get("question"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String answer = list2.get("answer"); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Log.i("abc", "question:" + question + " | answer:" + answer); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return list; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /** <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 把输入流转换成字符数组 <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @param inputStream&nbsp;&nbsp; 输入流 <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @return&nbsp; 字符数组 <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @throws Exception <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */ &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static byte[] readStream(InputStream inputStream) throws Exception { &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ByteArrayOutputStream bout = new ByteArrayOutputStream(); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; byte[] buffer = new byte[1024]; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int len = 0; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while ((len = inputStream.read(buffer)) != -1) { &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bout.write(buffer, 0, len); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bout.close(); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inputStream.close(); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return bout.toByteArray(); &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; }&nbsp;</div><img src ="http://www.blogjava.net/yxj1314520/aggbug/398231.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yxj1314520/" target="_blank">姚先进</a> 2013-04-22 20:21 <a href="http://www.blogjava.net/yxj1314520/archive/2013/04/22/398231.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>首先说一下Json数据的最基本的特点</title><link>http://www.blogjava.net/yxj1314520/archive/2013/04/22/398230.html</link><dc:creator>姚先进</dc:creator><author>姚先进</author><pubDate>Mon, 22 Apr 2013 11:11:00 GMT</pubDate><guid>http://www.blogjava.net/yxj1314520/archive/2013/04/22/398230.html</guid><wfw:comment>http://www.blogjava.net/yxj1314520/comments/398230.html</wfw:comment><comments>http://www.blogjava.net/yxj1314520/archive/2013/04/22/398230.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yxj1314520/comments/commentRss/398230.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yxj1314520/services/trackbacks/398230.html</trackback:ping><description><![CDATA[<div><br /> <p style="line-height:25px;text-indent:nullem;text-align:left">首先说一下Json数据的最基本的特点，Json数据是一系列的键值对的集合,和XML数据来比，Json数据的体积更加小，传输效率高，易解析，不过可读性不高;</p><p style="line-height:25px;text-indent:nullem;text-align:left">&nbsp; &nbsp;&nbsp; &nbsp;因为这次要从服务器端得到Json数据，并且通过解析之后把解析后的数据显示在Android客户端中，首先部署服务器端代码(直接使用Jsp/Servlet):</p><p style="line-height:25px;text-indent:nullem;text-align:left">&nbsp; &nbsp;&nbsp; &nbsp; 构造的Json数据如下:</p><p style="line-height:25px;text-indent:nullem;text-align:left">&nbsp; &nbsp;&nbsp;&nbsp;[{"name":"张三","address":"北京","age":20},{"name":"李四","address":"上海","age":30},{"name":"王五","address":"深圳","age":35}]</p><p style="line-height:25px;text-indent:nullem;text-align:left"><br /> </p><p style="line-height:25px;text-indent:nullem;text-align:left">[一]服务器端(Person.java省略):</p><p style="line-height:25px;text-indent:nullem;text-align:left">&nbsp; &nbsp;&nbsp;&nbsp;&#9312;:数据构造JsonService.java</p><div><div id="code_I3D"><ol><li>&lt;span style="font-size: 16px; "&gt;public class JsonService {<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;public static List&lt;Person&gt; getListPerson() {<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; List&lt;Person&gt; mLists = new ArrayList&lt;Person&gt;();<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; mLists.add(new Person("张三", "北京", 20));<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; mLists.add(new Person("李四", "上海", 30));<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; mLists.add(new Person("王五", "深圳", 35));<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; return mLists;<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}&lt;/span&gt;</li></ol></div><em>复制代码</em></div>&nbsp; &nbsp;&#9313;:Servlet的代码（包括构造Json数据，没有使用Json数据转换方法）JsonServlet.java<br /> <div><div id="code_qXC"><ol><li>&lt;span style="font-size: 16px; "&gt;public void doGet(HttpServletRequest request, HttpServletResponse response)<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;throws ServletException, IOException {<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; response.setContentType("text/html");<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; response.setCharacterEncoding("UTF-8");<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; PrintWriter out = response.getWriter();<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; List&lt;Person&gt; persons = JsonService.getListPerson();<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; StringBuffer sb = new StringBuffer();<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; sb.append('[');<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; for (Person person : persons) {<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;sb.append('{').append("\"name\":").append("\""+person.getName()+"\"").append(<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; ",");<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;sb.append("\"address\":").append("\""+person.getAddress()+"\"").append(",");<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;sb.append("\"age\":").append(person.getAge());<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;sb.append('}').append(",");<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; sb.deleteCharAt(sb.length() - 1);<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; sb.append(']');<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; out.write(new String(sb));<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; out.flush();<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; out.close();<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}&lt;/span&gt;</li></ol></div><em>复制代码</em></div><div><div id="code_wbp"><ol><li>&lt;span style="font-size: 16px; "&gt;<br /> </li><li>&lt;/span&gt;</li></ol></div><em>复制代码</em></div>&nbsp;&nbsp;&#9314;:部署到Tomact 浏览器输入<a href="http://localhost/JsonWeb/JsonServlet" target="_blank">http://localhost/JsonWeb/JsonServlet</a>直接访问结果如下:   <img _load="1" id="aimg_17781" src="http://www.apkbus.com/data/attachment/forum/201203/15/091351d010ddhbd99q9h59.gif" alt="0_1330066556axYL.gif" title="0_1330066556axYL.gif" width="600" />     &nbsp; &nbsp;&nbsp; &nbsp; 至此服务器端代码编码完成，下面进行客户端代码编写;&nbsp; &nbsp; (二)客户端(Person类，和展示数据的布局文件因为简单省去)<br /> &nbsp; &nbsp;&nbsp; &nbsp;&#9312;:获取服务器端的Json数据并且解析的工具类JsonParse.java<br /> &nbsp;&nbsp;必要的需要导入的包省去&nbsp;&nbsp;<div><div id="code_zLQ"><ol><li>&lt;span style="font-size:18px;"&gt;public class JsonParse {<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;/**<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;* 解析Json数据<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;* <br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;* @param urlPath<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;* @return mlists<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;* @throws Exception<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;*/<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;public static List&lt;Person&gt; getListPerson(String urlPath) throws Exception {<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; List&lt;Person&gt; mlists = new ArrayList&lt;Person&gt;();<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; byte[] data = readParse(urlPath);<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; JSONArray array = new JSONArray(new String(data));<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; for (int i = 0; i &lt; array.length(); i++) {<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;JSONObject item = array.getJSONObject(i);<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;String name = item.getString("name");<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;String address = item.getString("address");<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;int age = item.getInt("age");<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;mlists.add(new Person(name, address, age));<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; return mlists;<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;/**<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;* 从指定的url中获取字节数组<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;* <br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;* @param urlPath<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;* @return 字节数组<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;* @throws Exception<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;*/<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;public static byte[] readParse(String urlPath) throws Exception {<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; ByteArrayOutputStream outStream = new ByteArrayOutputStream();<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; byte[] data = new byte[1024];<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; int len = 0;<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; URL url = new URL(urlPath);<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; HttpURLConnection conn = (HttpURLConnection) url.openConnection();<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; InputStream inStream = conn.getInputStream();<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; while ((len = inStream.read(data)) != -1) {<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;outStream.write(data, 0, len);<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; inStream.close();<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; return outStream.toByteArray();<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /> </li><li>}&lt;/span&gt;</li></ol></div><em>复制代码</em></div>&#9313;:主Activity类<div><div id="code_K7Y"><ol><li>&lt;pre name="code" class="java"&gt;public class MainActivity extends Activity {<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;private Button mButton;<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;private ListView mListView;<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//使用IP不能使用localhost或者127.0.0.1，因为android模拟器默认绑定这个IP，这里应该访问局域网IP<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;private static final String urlPath = "http://10.16.31.207/JsonWeb/JsonServlet";<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;private static final String TAG = "MainActivity";<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;private List&lt;Person&gt; persons;<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;@Override<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;public void onCreate(Bundle savedInstanceState) {<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; super.onCreate(savedInstanceState);<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; setContentView(R.layout.main);<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; mButton = (Button) findViewById(R.id.button1);<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; mListView = (ListView) findViewById(R.id.listView1);<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; mButton.setOnClickListener(new MyOnClickListener());<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /> </li><li><br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;private class MyOnClickListener implements OnClickListener {<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; @Override<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; public void onClick(View v) {<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;try {<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 得到Json解析成功之后数据<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;persons = JsonParse.getListPerson(urlPath);<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;List&lt;HashMap&lt;String,  Object&gt;&gt; data = new ArrayList&lt;HashMap&lt;String,  Object&gt;&gt;();<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;for (int i = 0; i &lt; persons.size(); i++) {<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; HashMap&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; map.put("name", persons.get(i).getName());<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; map.put("address", persons.get(i).getAddress());<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; map.put("age", persons.get(i).getAge());<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; data.add(map);<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//初始化适配器，并且绑定数据<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SimpleAdapter _Adapter = new SimpleAdapter(MainActivity.this,<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;data, R.layout.listview_item, new String[] { "name",<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; "address", "age" }, new int[] { R.id.textView1,<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; R.id.textView2, R.id.textView3 });<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;mListView.setAdapter(_Adapter);<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;} catch (Exception e) {<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Toast.makeText(MainActivity.this, "解析失败", 2000).show();<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Log.i(TAG, e.toString());<br /> </li><li><br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br /> </li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}</li></ol></div><em>复制代码</em></div>至此服务器端和客户端编码介绍，运行android应用结果截图:<br />    <img _load="1" id="aimg_17782" src="http://www.apkbus.com/data/attachment/forum/201203/15/091351245aazsdda5y5sgq.gif" alt="0_1330067381FcfP.gif" title="0_1330067381FcfP.gif" width="254" />     <br />    <img src="http://www.apkbus.com/static/image/filetype/zip.gif" alt="" border="0" /> <span style="white-space: nowrap" id="attach_17783">  <a href="http://www.apkbus.com/forum.php?mod=attachment&amp;aid=MTc3ODN8YmRiMjQ1YzB8MTM2NjYwMjg2OXwwfDI0MDk4" target="_blank">Json数据解析服务器端加客户端代码.zip</a>  <em>(75.08 KB, 下载次数: 1309)</em> </span>    <br /> <br /> <br /> <br />   <div id="comment_140577"> </div> <dl id="ratelog_140577"><dt> <strong><a href="http://www.apkbus.com/forum.php?mod=misc&amp;action=viewratings&amp;tid=24098&amp;pid=140577" title="已有1人评分, 查看全部评分">1</a></strong> <p><a href="http://www.apkbus.com/forum.php?mod=misc&amp;action=viewratings&amp;tid=24098&amp;pid=140577">查看全部评分</a></p> </dt><dd>  <ul><li> <p id="rate_140577_9522"  mbn"=""><a href="http://www.apkbus.com/space-uid-9522.html" target="_blank"><img src="http://www.apkbus.com/uc_server/avatar.php?uid=9522&amp;size=small"  alt="" /></a></p> <p><a href="http://www.apkbus.com/space-uid-9522.html" target="_blank">lingdududu</a></p> </li></ul> </dd></dl></div><img src ="http://www.blogjava.net/yxj1314520/aggbug/398230.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yxj1314520/" target="_blank">姚先进</a> 2013-04-22 19:11 <a href="http://www.blogjava.net/yxj1314520/archive/2013/04/22/398230.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>首先客户端从服务器端获取json数据</title><link>http://www.blogjava.net/yxj1314520/archive/2013/04/22/398229.html</link><dc:creator>姚先进</dc:creator><author>姚先进</author><pubDate>Mon, 22 Apr 2013 11:10:00 GMT</pubDate><guid>http://www.blogjava.net/yxj1314520/archive/2013/04/22/398229.html</guid><wfw:comment>http://www.blogjava.net/yxj1314520/comments/398229.html</wfw:comment><comments>http://www.blogjava.net/yxj1314520/archive/2013/04/22/398229.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yxj1314520/comments/commentRss/398229.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yxj1314520/services/trackbacks/398229.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 、利用HttpUrlConnection   1 /**  2      * 从指定的URL中获取数组  3      * @param urlPath  4      * @return  5      * @throws Exception  6      */  7     public static String readParse(String urlPath) throws Excep...&nbsp;&nbsp;<a href='http://www.blogjava.net/yxj1314520/archive/2013/04/22/398229.html'>阅读全文</a><img src ="http://www.blogjava.net/yxj1314520/aggbug/398229.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yxj1314520/" target="_blank">姚先进</a> 2013-04-22 19:10 <a href="http://www.blogjava.net/yxj1314520/archive/2013/04/22/398229.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>