Search in sources :

Example 16 with JSONArray

use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.

the class Bug_for_jiangwei2 method test_for_jiangwei.

public void test_for_jiangwei() throws Exception {
    //		String str = "[2,'韩国篮球联赛','仁川大象(男篮)','首尔SK骑士 男篮',['大/小',3],'总进球 : 138.5 @ 0-0','','大','0.66','',1,25,200,1,0,0,'True','False',0,'','','',0,0,19819905,1,'h',145528,0]";
    //		JSONArray array = JSON.parseArray(str);
    String str = "[]";
    str = "[]";
    JSONArray array = JSON.parseArray(str);
}
Also used : JSONArray(com.alibaba.fastjson.JSONArray)

Example 17 with JSONArray

use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.

the class Bug_for_liuying method test_for_bug.

public void test_for_bug() throws Exception {
    String aa = "[{\"dictFont\":\"\",\"dictId\":\"wap\",\"dictName\":\"无线&手淘\"},{\"dictFont\":\"\",\"dictId\":\"etao\",\"dictName\":\"搜索\"}]";
    JSONObject jsonResult = new JSONObject();
    JSONArray jsonArray = JSONArray.parseArray(aa);
    jsonResult.put("aaa", jsonArray);
    System.out.println(jsonResult);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray)

Example 18 with JSONArray

use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.

the class Bug_for_issue_430 method test_for_issue.

public void test_for_issue() throws Exception {
    String text = "[{\"@type\": \"com.alibaba.json.bvt.bug.Bug_for_issue_430$FooModel\", \"fooCollection\": null}, {\"@type\": \"com.alibaba.json.bvt.bug.Bug_for_issue_430$FooModel\", \"fooCollection\": null}]";
    JSONArray array = JSON.parseArray(text);
    Assert.assertEquals(FooModel.class, array.get(0).getClass());
    Assert.assertEquals(FooModel.class, array.get(1).getClass());
    Assert.assertNull(((FooModel) array.get(0)).fooCollection);
    Assert.assertNull(((FooModel) array.get(1)).fooCollection);
}
Also used : JSONArray(com.alibaba.fastjson.JSONArray)

Example 19 with JSONArray

use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.

the class StackTraceElementTest method test_stackTrace.

public void test_stackTrace() throws Exception {
    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    String text = JSON.toJSONString(stackTrace, SerializerFeature.WriteClassName);
    JSONArray array = (JSONArray) JSON.parse(text);
    for (int i = 0; i < array.size(); ++i) {
        StackTraceElement element = (StackTraceElement) array.get(i);
        Assert.assertEquals(stackTrace[i].getFileName(), element.getFileName());
        Assert.assertEquals(stackTrace[i].getLineNumber(), element.getLineNumber());
        Assert.assertEquals(stackTrace[i].getClassName(), element.getClassName());
        Assert.assertEquals(stackTrace[i].getMethodName(), element.getMethodName());
    }
}
Also used : JSONArray(com.alibaba.fastjson.JSONArray)

Example 20 with JSONArray

use of com.alibaba.fastjson.JSONArray in project fastjson by alibaba.

the class Issue74 method test_for_issue.

public void test_for_issue() throws Exception {
    InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue74.json");
    String text = org.apache.commons.io.IOUtils.toString(is);
    is.close();
    JSONArray json = (JSONArray) JSON.parse(text);
    Assert.assertNotNull(json.getJSONObject(0).getJSONObject("dataType").getJSONObject("categoryType").getJSONArray("dataTypes").get(0));
    Assert.assertSame(json.getJSONObject(0).getJSONObject("dataType"), json.getJSONObject(0).getJSONObject("dataType").getJSONObject("categoryType").getJSONArray("dataTypes").get(0));
}
Also used : InputStream(java.io.InputStream) JSONArray(com.alibaba.fastjson.JSONArray)

Aggregations

JSONArray (com.alibaba.fastjson.JSONArray)93 JSONObject (com.alibaba.fastjson.JSONObject)37 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)8 List (java.util.List)7 StringReader (java.io.StringReader)6 DefaultJSONParser (com.alibaba.fastjson.parser.DefaultJSONParser)5 JSONReaderScanner (com.alibaba.fastjson.parser.JSONReaderScanner)5 Reader (java.io.Reader)5 WXSDKInstanceTest (com.taobao.weex.WXSDKInstanceTest)4 HashMap (java.util.HashMap)4 Test (org.testng.annotations.Test)4 IOException (java.io.IOException)3 BigDecimal (java.math.BigDecimal)3 ParseException (java.text.ParseException)3 Setting (org.aisen.android.common.setting.Setting)3 JSONReader (com.alibaba.fastjson.JSONReader)2 InputStream (java.io.InputStream)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2