JSON for Java 源代码
将源代码发布一下与大家一起探讨,不足之处请大家不吝赐教。
1.测试文件:
test.json
/**
* 测试JSON
*
*/
{
id:-NaN, //ID
$name_1:"johnson\"李\"+\"test\"", //姓名
married:false,
hobby:[
"programming"
]
}
2.测试代码
package org.zergle.json;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import org.zergle.json.utils.JsonOutputFormat;
public class TestJsonReader {
/**
* 测试从文件解析JSON
* @param args
*/
public static void main(String[] args) {
JsonReader reader = null;
JsonWriter writer = null;
try {
reader = new JsonReader(new InputStreamReader(TestJsonReader.class.getResourceAsStream("/test.json")));
JsonObject json = reader.readJsonObject();
writer = new JsonWriter(new OutputStreamWriter(System.out));
writer.write(json, new JsonOutputFormat());
writer.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (reader != null) {
reader.close();
reader = null;
}
if (writer != null) {
writer.close();
writer = null;
}
} catch (IOException e) { }
}
}
}
最新下载:
http://code.google.com/p/json/downloads/list
申请的project名称 JSON 通过了,最近更新请访问下面这个地址:
http://code.google.com/p/jsonex/
svn checkout http://jsonex.googlecode.com/svn/trunk/ jsonex-read-only
正式命名JSON API 为JSONEX,在下面地址可以获取源码:
svn checkout http://jsonex.googlecode.com/svn/trunk/ jsonex-read-only