本文整理汇总了Java中com.alibaba.fastjson.JSONReader类的典型用法代码示例。如果您正苦于以下问题:Java JSONReader类的具体用法?Java JSONReader怎么用?Java JSONReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JSONReader类属于com.alibaba.fastjson包,在下文中一共展示了JSONReader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: test_cn
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
public void test_cn() throws Exception {
Model vo = new JSONReader(new StringReader("{\"date0\":\"2016-05-06\",\"date1\":\"2017-03-01\"}")).readObject(Model.class);
Calendar calendar = Calendar.getInstance(JSON.defaultTimeZone, JSON.defaultLocale);
calendar.setTime(vo.date0);
assertEquals(2016, calendar.get(Calendar.YEAR));
assertEquals(4, calendar.get(Calendar.MONTH));
assertEquals(6, calendar.get(Calendar.DAY_OF_MONTH));
assertEquals(0, calendar.get(Calendar.HOUR_OF_DAY));
assertEquals(0, calendar.get(Calendar.MINUTE));
assertEquals(0, calendar.get(Calendar.SECOND));
assertEquals(0, calendar.get(Calendar.MILLISECOND));
calendar.setTime(vo.date1);
assertEquals(2017, calendar.get(Calendar.YEAR));
assertEquals(2, calendar.get(Calendar.MONTH));
assertEquals(1, calendar.get(Calendar.DAY_OF_MONTH));
assertEquals(0, calendar.get(Calendar.HOUR_OF_DAY));
assertEquals(0, calendar.get(Calendar.MINUTE));
assertEquals(0, calendar.get(Calendar.SECOND));
assertEquals(0, calendar.get(Calendar.MILLISECOND));
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:DateFieldTest11_reader.java
示例2: test_read
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
public void test_read() throws Exception {
JSONReader reader = new JSONReader(new StringReader(text));
reader.startObject();
int count = 0;
while (reader.hasNext()) {
String key = (String) reader.readObject();
Object value = reader.readObject();
Assert.assertNotNull(key);
Assert.assertNotNull(value);
count++;
}
Assert.assertEquals(10, count);
reader.endObject();
reader.close();
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:JSONReaderTest_object_object.java
示例3: test_read
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
public void test_read() throws Exception {
String text = "{\"f0\":0,\"f1\":1,\"f2\":2,\"f3\":3,\"f4\":4, " + //
"\"f5\":5,\"f6\":6,\"f7\":7,\"f8\":8,\"f9\":9}";
JSONReader reader = new JSONReader(new StringReader(text));
reader.startObject();
int count = 0;
while (reader.hasNext()) {
String key = (String) reader.readObject();
Integer value = reader.readInteger();
count++;
}
Assert.assertEquals(10, count);
reader.endObject();
reader.close();
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:JSONReaderTest_object_int.java
示例4: test_e
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
public void test_e() throws Exception {
Exception error = null;
try {
StringBuilder buf = new StringBuilder();
buf.append("[{\"type\":\"");
for (int i = 0; i < 8180; ++i) {
buf.append('A');
}
buf.append("\\t");
JSONReader reader = new JSONReader(new MyReader(buf.toString()));
reader.readObject();
reader.close();
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:JSONReaderScannerTest_error4.java
示例5: deserialze
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
@Override
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
JSONReader reader = new JSONReader(parser);
reader.startObject();
String key = reader.readString();
Integer value = reader.readInteger();
Model model = new Model();
model.id = value;
reader.endObject();
// TODO Auto-generated method stub
return (T) model;
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:CustomDeserializerTest.java
示例6: test_1
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
public void test_1() throws Exception {
String json = "{\"v1\":-1883391953414482124,\"v2\":-3019416596934963650,\"v3\":6497525620823745793,\"v4\":2136224289077142499,\"v5\":-2090575024006307745}";
String json2 = "{\"v1\":\"-1883391953414482124\",\"v2\":\"-3019416596934963650\",\"v3\":\"6497525620823745793\",\"v4\":\"2136224289077142499\",\"v5\":\"-2090575024006307745\"}";
Model m1 = new JSONReader(new StringReader(json)).readObject(Model.class);
Model m2 = new JSONReader(new StringReader(json2)).readObject(Model.class);
assertNotNull(m1);
assertNotNull(m2);
assertEquals(-1883391953414482124L, m1.v1.longValue());
assertEquals(-3019416596934963650L, m1.v2.longValue());
assertEquals(6497525620823745793L, m1.v3.longValue());
assertEquals(2136224289077142499L, m1.v4.longValue());
assertEquals(-2090575024006307745L, m1.v5.longValue());
assertEquals(-1883391953414482124L, m2.v1.longValue());
assertEquals(-3019416596934963650L, m2.v2.longValue());
assertEquals(6497525620823745793L, m2.v3.longValue());
assertEquals(2136224289077142499L, m2.v4.longValue());
assertEquals(-2090575024006307745L, m2.v5.longValue());
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:LongTest2_obj.java
示例7: test_obj_3
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
public void test_obj_3() throws Exception {
JSONReader reader = new JSONReader(new StringReader("{\"val\":{\"val\":{\"id\":123}}}"));
reader.startObject();
Assert.assertEquals("val", reader.readString());
reader.startObject();
Assert.assertEquals("val", reader.readString());
reader.startObject();
Assert.assertEquals("id", reader.readString());
Assert.assertEquals(Long.valueOf(123), reader.readLong());
reader.endObject();
reader.endObject();
reader.endObject();
reader.close();
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:JSONReader_obj_3.java
示例8: test_read
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
public void test_read() throws Exception {
Field field = JSONReader.class.getDeclaredField("context");
field.setAccessible(true);
;
JSONReader reader = new JSONReader(new StringReader("[{}]"));
reader.config(Feature.AllowArbitraryCommas, true);
reader.startArray();
context = field.get(reader);
stateField = context.getClass().getDeclaredField("state");
stateField.setAccessible(true);
{
Exception error = null;
try {
reader.readObject(VO.class);
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:JSONReaderTest_error2.java
示例9: test_read
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
public void test_read() throws Exception {
JSONReader reader = new JSONReader(new StringReader(text));
reader.startArray();
int count = 0;
while (reader.hasNext()) {
reader.startObject();
reader.endObject();
count++;
}
Assert.assertEquals(10, count);
reader.endArray();
reader.close();
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:JSONReaderTest_array_object_2.java
示例10: test_read
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
public void test_read() throws Exception {
JSONReader reader = new JSONReader(new StringReader(text));
reader.startArray();
int count = 0;
while (reader.hasNext()) {
Object item = reader.readObject();
Assert.assertEquals(JSONArray.class, item.getClass());
count++;
}
Assert.assertEquals(10, count);
reader.endArray();
reader.close();
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:JSONReaderTest_array_array.java
示例11: test_list
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
public void test_list() throws Exception {
String text = "{\"values\":[\"a\",null,\"b\",\"ab\\\\c\\\"\"]}";
JSONReader reader = new JSONReader(new StringReader(text));
Model model = reader.readObject(Model.class);
Assert.assertEquals(4, model.values.size());
Assert.assertEquals("a", model.values.get(0));
Assert.assertEquals(null, model.values.get(1));
Assert.assertEquals("b", model.values.get(2));
Assert.assertEquals("ab\\c\"", model.values.get(3));
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:ListStringFieldTest_stream.java
示例12: test_int_error_end
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
public void test_int_error_end() throws Exception {
Exception error = null;
try {
JSONReader reader = new JSONReader(new StringReader("{\"value\":1001,\"value2\":-2001["));
reader.readObject(Model.class);
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:ReaderIntFieldTest.java
示例13: test_special_2
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
public void test_special_2() throws Exception {
Model model = new Model();
model.name = "a\\bc\"";
String text = JSON.toJSONString(model);
Assert.assertEquals("{\"name\":\"a\\\\bc\\\"\"}", text);
JSONReader reader = new JSONReader(new StringReader(text));
Model model2 = reader.readObject(Model.class);
Assert.assertEquals(model.name, model2.name);
reader.close();
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:StringFieldTest_special.java
示例14: test_error_null
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
public void test_error_null() throws Exception {
String text = "[null";
JSONReader reader = new JSONReader(new StringReader(text));
Exception error = null;
try {
reader.readObject(Model.class);
reader.close();
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:ListStringFieldTest_stream_array.java
示例15: test_e
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
public void test_e() throws Exception {
Exception error = null;
try {
new JSONReader(new MyReader());
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:JSONReaderScannerTest_error.java
示例16: test_error_overflow_stream
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
public void test_error_overflow_stream() throws Exception {
String text = "[2147483649:\"wenshao\" ]";
Exception error = null;
try {
JSONReader reader = new JSONReader(new StringReader(text), Feature.SupportArrayToBean);
reader.readObject(VO.class);
reader.close();
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:WriteAsArray_long_public.java
示例17: test_error_value_notmatch_stream
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
public void test_error_value_notmatch_stream() throws Exception {
String text = "[true,\"wenshao\"]";
Exception error = null;
try {
JSONReader reader = new JSONReader(new StringReader(text), Feature.SupportArrayToBean);
reader.readObject(VO.class);
reader.close();
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:WriteAsArray_long_public.java
示例18: test_error_value_notmatch_2_stream
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
public void test_error_value_notmatch_2_stream() throws Exception {
String text = "[+,\"wenshao\"]";
Exception error = null;
try {
JSONReader reader = new JSONReader(new StringReader(text), Feature.SupportArrayToBean);
reader.readObject(VO.class);
reader.close();
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:WriteAsArray_long_public.java
示例19: test_error_null
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
public void test_error_null() throws Exception {
String text = "{\"values\":[null";
JSONReader reader = new JSONReader(new StringReader(text));
Exception error = null;
try {
reader.readObject(Model.class);
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:ListStringFieldTest_stream.java
示例20: test_null_array_reader
import com.alibaba.fastjson.JSONReader; //导入依赖的package包/类
public void test_null_array_reader() throws Exception {
JSONReader reader = new JSONReader(new StringReader("[\"null\" ,\"null\"]"), Feature.SupportArrayToBean);
Model model = reader.readObject(Model.class);
assertNotNull(model);
assertNull(model.v1);
assertNull(model.v2);
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:LongNullTest.java
注:本文中的com.alibaba.fastjson.JSONReader类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论