Search in sources :

Example 46 with JSONObject

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

the class JSONObjectTest method test_getLong_1.

public void test_getLong_1() throws Exception {
    JSONObject json = new JSONObject(false);
    json.put("A", 55L);
    json.put("B", 55);
    Assert.assertEquals(json.getLong("A").longValue(), 55L);
    Assert.assertEquals(json.getLong("B").longValue(), 55L);
    Assert.assertEquals(json.getLong("C"), null);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 47 with JSONObject

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

the class JSONObjectTest method test_getBoolean.

public void test_getBoolean() throws Exception {
    JSONObject json = new JSONObject();
    json.put("A", true);
    Assert.assertEquals(json.getBoolean("A").booleanValue(), true);
    Assert.assertEquals(json.getLong("C"), null);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 48 with JSONObject

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

the class JSONObjectTest method test_getLong.

public void test_getLong() throws Exception {
    JSONObject json = new JSONObject(true);
    json.put("A", 55L);
    json.put("B", 55);
    json.put("K", true);
    Assert.assertEquals(json.getLong("A").longValue(), 55L);
    Assert.assertEquals(json.getLong("B").longValue(), 55L);
    Assert.assertEquals(json.getLong("C"), null);
    Assert.assertEquals(json.getBooleanValue("K"), true);
    Assert.assertEquals(json.getBoolean("K"), Boolean.TRUE);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 49 with JSONObject

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

the class JSONObjectTest method test_getDate.

public void test_getDate() throws Exception {
    long currentTimeMillis = System.currentTimeMillis();
    JSONObject json = new JSONObject();
    json.put("A", new Date(currentTimeMillis));
    json.put("B", currentTimeMillis);
    Assert.assertEquals(json.getDate("A").getTime(), currentTimeMillis);
    Assert.assertEquals(json.getDate("B").getTime(), currentTimeMillis);
    Assert.assertEquals(json.getLong("C"), null);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) Date(java.util.Date)

Example 50 with JSONObject

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

the class JSONObjectTest method test_getObject.

public void test_getObject() throws Exception {
    JSONObject json = new JSONObject();
    json.put("obj", new JSONObject());
    Assert.assertEquals(0, json.getJSONObject("obj").size());
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

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