use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class JSONReaderScannerTest_decimal method test_scanInt.
public void test_scanInt() throws Exception {
StringBuffer buf = new StringBuffer();
buf.append('[');
for (int i = 0; i < 1024; ++i) {
if (i != 0) {
buf.append(',');
}
buf.append(i + ".0");
}
buf.append(']');
Reader reader = new StringReader(buf.toString());
JSONReaderScanner scanner = new JSONReaderScanner(reader);
DefaultJSONParser parser = new DefaultJSONParser(scanner);
JSONArray array = (JSONArray) parser.parse();
for (int i = 0; i < array.size(); ++i) {
BigDecimal value = new BigDecimal(i + ".0");
Assert.assertEquals(value, array.get(i));
}
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class JSONReaderScannerTest_int method test_scanInt.
public void test_scanInt() throws Exception {
StringBuffer buf = new StringBuffer();
buf.append('[');
for (int i = 0; i < 1024; ++i) {
if (i != 0) {
buf.append(',');
}
buf.append(i);
}
buf.append(']');
Reader reader = new StringReader(buf.toString());
JSONReaderScanner scanner = new JSONReaderScanner(reader);
DefaultJSONParser parser = new DefaultJSONParser(scanner);
JSONArray array = (JSONArray) parser.parse();
for (int i = 0; i < array.size(); ++i) {
Assert.assertEquals(i, ((Integer) array.get(i)).intValue());
}
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class TypeUtilsTest3 method test_ex.
public void test_ex() throws Exception {
RuntimeException ex = new RuntimeException();
JSONObject object = (JSONObject) JSON.toJSON(ex);
JSONArray array = object.getJSONArray("stackTrace");
array.getJSONObject(0).put("lineNumber", null);
JSON.parseObject(object.toJSONString(), Exception.class);
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class TypeUtilsToJSONTest method test_1.
public void test_1() throws Exception {
List list = new ArrayList();
JSONArray json = (JSONArray) JSON.toJSON(list);
Assert.assertEquals(list.size(), json.size());
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class JSONPath_array_remove_0 method test_remove.
public void test_remove() throws Exception {
JSONObject jsonObject = new JSONObject();
JSONArray array = new JSONArray();
for (int i = 0; i < 10; ++i) {
JSONObject item = new JSONObject();
item.put("age", i);
array.add(item);
}
jsonObject.put("aaa", array);
//解析出错
JSONPath.remove(jsonObject, "$.aaa[0:1].age");
//解析出错
JSONPath.remove(jsonObject, "$.aaa[0,1].age");
//解析正确
JSONPath.remove(jsonObject, "$.aaa[0].age");
}
Aggregations