use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class StringTest_02 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 JSONReader_array method test_array.
public void test_array() throws Exception {
JSONReader reader = new JSONReader(new StringReader("[[],[],3,null,{\"name\":\"jobs\"},{\"id\":123},{\"id\":1},{\"id\":2}]"));
reader.startArray();
JSONArray first = (JSONArray) reader.readObject();
JSONArray second = (JSONArray) reader.readObject();
Assert.assertNotNull(first);
Assert.assertNotNull(second);
Assert.assertEquals(new Integer(3), reader.readInteger());
Assert.assertNull(reader.readString());
{
Map<String, Object> map = new HashMap<String, Object>();
reader.readObject(map);
Assert.assertEquals("jobs", map.get("name"));
}
{
VO vo = new VO();
reader.readObject(vo);
Assert.assertEquals(123, vo.getId());
}
while (reader.hasNext()) {
VO vo = reader.readObject(VO.class);
Assert.assertNotNull(vo);
}
reader.endArray();
reader.close();
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class RefTest17 method test_0.
public void test_0() throws Exception {
Person pA = new Person("a");
Person pB = new Person("b");
Family fA = new Family();
fA.setMembers(new Person[] { pA, pB });
fA.setMaster(pA);
Person pC = new Person("c");
Person pD = new Person("d");
Family fB = new Family();
fB.setMembers(new Person[] { pC, pD });
fB.setMaster(pC);
Family[] familyArray = new Family[] { fA, fB };
String text = JSON.toJSONString(familyArray, true);
System.out.println(text);
JSONArray array = JSON.parseArray(text);
Assert.assertSame(array.getJSONObject(0).get("master"), array.getJSONObject(0).getJSONArray("members").get(0));
Family family = array.getObject(0, Family.class);
Assert.assertNotNull(family.getMembers()[0]);
Assert.assertNotNull(family.getMembers()[1]);
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class RefTest18 method test_array.
public void test_array() throws Exception {
String text = "{\"b\":{},\"a\":[{\"$ref\":\"$.b\"}]}";
JSONObject obj = JSON.parseObject(text);
JSONArray array = obj.getJSONArray("a");
Assert.assertEquals(1, array.size());
Assert.assertNotNull(array.get(0));
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class Alipay1206 method test_for_alipay.
public void test_for_alipay() throws Exception {
File file = new File("/Users/wenshao/Downloads/x.txt");
String text = FileUtils.readFileToString(file);
JSONObject root = JSON.parseObject(text);
JSONObject resultObj = root.getJSONObject("resultObj");
assertNotNull(resultObj);
JSONArray conditionGroupItemList = resultObj.getJSONArray("conditionGroupItemList");
assertNotNull(conditionGroupItemList);
JSONObject conditionGroup = conditionGroupItemList.getJSONObject(0).getJSONObject("conditionGroup");
assertNotNull(conditionGroup);
JSONArray recordList = conditionGroup.getJSONArray("recordList");
assertNotNull(recordList);
JSONArray conditionItemList = recordList.getJSONObject(0).getJSONArray("conditionItemList");
assertNotNull(conditionItemList);
JSONObject condition = conditionItemList.getJSONObject(18).getJSONObject("condition");
assertNotNull(condition);
JSONArray conditionConstraint = condition.getJSONArray("conditionConstraint");
assertNotNull(conditionConstraint);
JSONObject constraintOptionalRecordMap = conditionConstraint.getJSONObject(0).getJSONObject("constraintOptionalRecordMap");
assertNotNull(constraintOptionalRecordMap);
System.out.println(constraintOptionalRecordMap);
}
Aggregations