﻿<?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>IT博客-我心飞扬-文章分类-Tail</title><link>http://www.cnitblog.com/thinke365/category/8426.html</link><description /><language>zh-cn</language><lastBuildDate>Sun, 02 Oct 2011 19:35:29 GMT</lastBuildDate><pubDate>Sun, 02 Oct 2011 19:35:29 GMT</pubDate><ttl>60</ttl><item><title>JSON</title><link>http://www.cnitblog.com/thinke365/articles/60960.html</link><dc:creator>Monicax</dc:creator><author>Monicax</author><pubDate>Mon, 24 Aug 2009 18:05:00 GMT</pubDate><guid>http://www.cnitblog.com/thinke365/articles/60960.html</guid><wfw:comment>http://www.cnitblog.com/thinke365/comments/60960.html</wfw:comment><comments>http://www.cnitblog.com/thinke365/articles/60960.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/thinke365/comments/commentRss/60960.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/thinke365/services/trackbacks/60960.html</trackback:ping><description><![CDATA[有人特定自己实现了一套JSON转换工具，其实必要性不是很大，可以直接使用JSON的官方实现，有各种语言的实现，当然也有Java实现。都是比较完备的实现。<br>当然，有时候也有必要自己实现一套JSON机制。<br><br>当格式固定，并只用到几种简单转换机制时，用JSON的官方Java实现，可能太重量级了，还要熟悉不少API，干脆自己实现得了。 实践中碰到这种情况也是很自然的。<br><br>话说回来，这里还是谈论 JSON的官方Java实现。<br><br>JSONTokener，是用于字符处理的。传入的并不是一个String，而是 reader，这种做法更合适于做大数据处理，更底层和通用化? <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.reader = reader.markSupported() ?&nbsp;reader : new BufferedReader(reader);&nbsp; // <span style="FONT-SIZE: 10pt; COLOR: red"><strong style="COLOR: #3366ff">还做了是否支持缓存读的判断?<br></strong></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如果仅仅是一般的String，也可以转换为Reader...<br><br>Exception里面可以放一个属性 Throwable,初始化对象时可以用到，也可以有getCause()方法<br><br>while (s.endsWith("0")) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s = s.substring(0, s.length() - 1);<br>}&nbsp; // 开源代码，<span style="FONT-SIZE: 10pt; COLOR: #008080">并不完全是毫无瑕疵的精品</span>。没有必要每次都做一次 substring的。 每次都要重新构建一个 字符串对象。其实可以修改为。<br>index = s.length()-1;<br>while(s.charAt(index) == "0") {<br>&nbsp;&nbsp;&nbsp;&nbsp; index --;<br>}<br>s = s.substring(0, index); // 这样的代码，效率会稍微高一些吧。<br><br>
<img src ="http://www.cnitblog.com/thinke365/aggbug/60960.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/thinke365/" target="_blank">Monicax</a> 2009-08-25 02:05 <a href="http://www.cnitblog.com/thinke365/articles/60960.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>