use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class Issue771 method test_for_issue.
public void test_for_issue() throws Exception {
SerializeWriter writer = new SerializeWriter(null, JSON.DEFAULT_GENERATE_FEATURE, new SerializerFeature[0]);
int defaultBufferSize = writer.getBufferLength();
String encoded = JSON.toJSONString(new FooBar(defaultBufferSize));
JSONObject decoded = (JSONObject) JSON.parse(encoded);
JSONArray dataToEncode = decoded.getJSONArray("dataToEncode");
Assert.assertEquals(5, dataToEncode.size());
writer.close();
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class Issue943 method test_for_issue.
public void test_for_issue() throws Exception {
String text = "{\n" + "\t\"symbols\":[\n" + "\t {\"id\":1,\"type\":\"SCATTER\"},\n" + "\t {\"id\":2,\"type\":\"BONUS\"}\n" + "\t]\n" + "}";
JSONObject root = JSON.parseObject(text);
JSONArray symbols = root.getJSONArray("symbols");
assertNotNull(symbols);
assertEquals(2, symbols.size());
assertEquals(1, symbols.getJSONObject(0).get("id"));
assertEquals("SCATTER", symbols.getJSONObject(0).get("type"));
assertEquals(2, symbols.getJSONObject(1).get("id"));
assertEquals("BONUS", symbols.getJSONObject(1).get("type"));
SlotConfig slotConfig = JSON.parseObject(text, SlotConfig.class);
assertNotNull(slotConfig);
assertEquals(2, slotConfig.symbols.size());
assertEquals(1, slotConfig.symbols.get(0).getId());
assertEquals(SymbolType.SCATTER, slotConfig.symbols.get(0).getType());
assertEquals(2, slotConfig.symbols.get(1).getId());
assertEquals(SymbolType.BONUS, slotConfig.symbols.get(1).getType());
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class Issue955 method test_checkArray.
public void test_checkArray() throws Exception {
Art origin = makeOrigin();
JSONObject object = (JSONObject) JSON.toJSON(origin);
JSONArray jsonArray = new JSONArray();
jsonArray.add(object);
Art other = JSON.parseObject(jsonArray.getString(0), Art.class);
// test passed
assertSame(origin, other);
// return = null;
other = jsonArray.getObject(0, Art.class);
// test failed
assertSame(origin, other);
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class Issue780 method test_for_issue_array.
public void test_for_issue_array() throws Exception {
JSONObject json = new JSONObject();
json.put("robj", "[123]");
JSONArray robj = json.getJSONArray("robj");
assertEquals(123, robj.get(0));
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class JSONTest method testParseArray.
@Test
public void testParseArray() throws Exception {
List list = new ArrayList();
OuterEntry entry = new OuterEntry();
list.add(entry);
entry.setId(1000L);
entry.setUrl("http://www.springframework.org/schema/aop");
String jsonString = JSONObject.toJSONString(entry);
String arrayString = JSONObject.toJSONString(list);
System.out.println(jsonString);
System.out.println(arrayString);
list = JSONArray.parseArray(arrayString, OuterEntry.class);
// 这一步出错
JSONArray array = JSONArray.parseArray(arrayString);
}
Aggregations