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");
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class StringTest_00 method test_string.
public void test_string() throws Exception {
char[] chars = new char[1024];
Arrays.fill(chars, '0');
StringBuilder buf = new StringBuilder();
buf.append("[\"");
for (int i = 0; i < 16; ++i) {
buf.append("\\\\");
buf.append(new String(chars));
}
buf.append("\"]");
String text = buf.toString();
JSONArray array = (JSONArray) JSON.parse(text);
Assert.assertEquals(1, array.size());
String item = (String) array.get(0);
Assert.assertEquals(16 * 1024 + 16, item.length());
for (int i = 0; i < 16; ++i) {
Assert.assertTrue(item.charAt(i * 1025) == '\\');
for (int j = 0; j < 1024; ++j) {
Assert.assertTrue(item.charAt(i * 1025 + j + 1) == '0');
}
}
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class JSONPath_set_test2 method test_jsonpath.
public void test_jsonpath() throws Exception {
JSONObject rootObject = JSON.parseObject("{\"array\":[{},{},{},{}]}");
JSONPath.set(rootObject, "$.array[0:].key", "123");
JSONArray array = rootObject.getJSONArray("array");
for (int i = 0; i < array.size(); ++i) {
Assert.assertEquals("123", array.getJSONObject(i).get("key"));
}
System.out.println(rootObject);
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class RefTest5 method test_parse.
public void test_parse() throws Exception {
Object[] array2 = JSON.parseObject("[[{\"$ref\":\"..\"}]]", Object[].class);
JSONArray item = (JSONArray) array2[0];
Assert.assertSame(item, item.get(0));
}
Aggregations