use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class Alipay1213 method test_for_issue.
public void test_for_issue() throws Exception {
String text = "{\"resultObj\":{\"assetSize\":{},\"chargeTypeList\":[\"A\"],\"fundManagerMapList\":[{},{}],\"fundRateConvertList\":[{},{},{}],\"fundRateOperate\":{},\"fundRatePurchaseList\":[{\"fixedRate\":{},\"maxAmount\":{},\"minAmount\":{}}],\"fundRateRedeemList\":[{\"fixedRate\":{}}],\"fundRateSubscribeList\":[{\"fixedRate\":{},\"maxAmount\":{},\"minAmount\":{}}],\"fundRatingList\":[{},{}],\"fundRuleConvertList\":[{},{}],\"fundRuleConvertVoList\":[{\"fundRateConvertList\":[{\"$ref\":\"$.resultObj.fundRateConvertList[0]\"},{\"$ref\":\"$.resultObj.fundRateConvertList[1]\"}],\"fundRuleConvert\":{\"$ref\":\"$.resultObj.fundRuleConvertList[0]\"}},{\"fundRateConvertList\":[{\"$ref\":\"$.resultObj.fundRateConvertList[2]\"}],\"fundRuleConvert\":{\"$ref\":\"$.resultObj.fundRuleConvertList[1]\"}}]}}";
JSONObject root = JSON.parseObject(text);
JSONObject resultObj = root.getJSONObject("resultObj");
assertNotNull(resultObj);
JSONArray fundRuleConvertVoList = resultObj.getJSONArray("fundRuleConvertVoList");
assertNotNull(fundRuleConvertVoList);
JSONArray fundRateConvertList = fundRuleConvertVoList.getJSONObject(0).getJSONArray("fundRateConvertList");
assertNotNull(fundRateConvertList);
assertNotNull(fundRateConvertList.get(0));
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class JSONReaderScannerTest__map_string method test_scanInt.
public void test_scanInt() throws Exception {
StringBuffer buf = new StringBuffer();
buf.append('[');
for (int i = 0; i < 10; ++i) {
if (i != 0) {
buf.append(',');
}
// 1000000000000
//
buf.append("{\"id\":\"" + 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(Integer.toString(i), array.getJSONObject(i).get("id"));
}
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class JSONReaderScannerTest_long 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(',');
}
long value = (long) Integer.MAX_VALUE + 1L + (long) i;
buf.append(value);
}
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) {
long value = (long) Integer.MAX_VALUE + 1L + (long) i;
Assert.assertEquals(value, ((Long) array.get(i)).longValue());
}
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class JSONReaderTest method test_read.
public void test_read() throws Exception {
String resource = "2.json";
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
JSONReader reader = new JSONReader(new InputStreamReader(is, "UTF-8"));
reader.startObject();
Assert.assertEquals("company", reader.readString());
Assert.assertTrue(reader.readObject() instanceof JSONObject);
Assert.assertEquals("count", reader.readString());
Assert.assertEquals(5, reader.readObject());
Assert.assertEquals("pagecount", reader.readString());
Assert.assertEquals(0, reader.readObject());
Assert.assertEquals("pageindex", reader.readString());
Assert.assertEquals(0, reader.readObject());
Assert.assertEquals("resultList", reader.readString());
Assert.assertTrue(reader.readObject() instanceof JSONArray);
Assert.assertEquals("totalCount", reader.readString());
Assert.assertEquals(0, reader.readObject());
reader.endObject();
reader.close();
}
use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.
the class StringTest_01 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("\\\"");
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 + 32, item.length());
for (int i = 0; i < 16; ++i) {
Assert.assertTrue(item.charAt(i * 1026) == '\\');
Assert.assertTrue(item.charAt(i * 1026 + 1) == '\"');
for (int j = 0; j < 1024; ++j) {
Assert.assertTrue(item.charAt(i * 1026 + j + 2) == '0');
}
}
}
Aggregations