Search in sources :

Example 66 with JSONObject

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

the class Bug_for_agapple_2 method test_bug.

public void test_bug() throws Exception {
    DbMediaSource obj = new DbMediaSource();
    obj.setType(DataMediaType.ORACLE);
    JSONObject json = (JSONObject) JSON.toJSON(obj);
    Assert.assertEquals("ORACLE", json.get("type"));
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 67 with JSONObject

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

the class SlashTest method test_0.

public void test_0() throws Exception {
    String text = "{\"errorMessage\":\"resource '/rpc/hello/none.json' is not found !\"}";
    JSONObject json = (JSONObject) JSON.parse(text);
    Assert.assertEquals("{\"errorMessage\":\"resource '/rpc/hello/none.json' is not found !\"}", json.toString());
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 68 with JSONObject

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

the class Bug_for_zhongyin method test_map.

public void test_map() throws Exception {
    for (char c = ''; c < ' '; c++) {
        String s = String.valueOf(c) + "map";
        String jsons = JSON.toJSONString(Collections.singletonMap("value", s));
        System.out.println(jsons);
        JSONObject o = JSON.parseObject(jsons);
        Assert.assertEquals(s, o.getString("value"));
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 69 with JSONObject

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

the class Bug_for_zhongyin method test_0.

public void test_0() throws Exception {
    String hex = "41544D20E58F96E78EB0EFBC8DE993B6E88194E5908CE59F8E1A20E4BD9BE5B1B1E5B882E7A685E59F8EE58CBAE7A596E5BA99E8B7AF201A33331A20E58FB7E799BEE88AB1E5B9BFE59CBAE9A696E5B182201A";
    String result = getHexStr(hex);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("aaa", result);
    String stringV = JSON.toJSONString(map);
    System.out.println(stringV);
    JSONObject o = JSON.parseObject(stringV);
    System.out.println(o.getString("aaa"));
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject)

Example 70 with JSONObject

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

the class Issue1030 method test_for_issue.

public void test_for_issue() throws Exception {
    String DOC = "{\"books\":[{\"pageWords\":[{\"num\":10},{\"num\":15}]},{\"pageWords\":[{\"num\":20}]}]}";
    //fastjson包
    JSONObject result = JSONObject.parseObject(DOC);
    List array = (List) JSONPath.eval(result, "$.books[0:].pageWords[0:]");
    assertEquals(3, array.size());
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) List(java.util.List)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)374 JSONArray (com.alibaba.fastjson.JSONArray)37 Test (org.junit.Test)32 DefaultJSONParser (com.alibaba.fastjson.parser.DefaultJSONParser)23 HashMap (java.util.HashMap)20 JSONException (com.alibaba.fastjson.JSONException)18 ArrayList (java.util.ArrayList)18 Date (java.util.Date)18 JSONReaderScanner (com.alibaba.fastjson.parser.JSONReaderScanner)14 IOException (java.io.IOException)12 Map (java.util.Map)12 WXSDKInstanceTest (com.taobao.weex.WXSDKInstanceTest)11 JSMethod (com.taobao.weex.annotation.JSMethod)11 WXBridgeManagerTest (com.taobao.weex.bridge.WXBridgeManagerTest)9 BigDecimal (java.math.BigDecimal)9 List (java.util.List)9 ValueStack (com.roof.chain.api.ValueStack)7 GenericValueStack (com.roof.chain.support.GenericValueStack)7 Gson (com.google.gson.Gson)6 BigInteger (java.math.BigInteger)5