Search in sources :

Example 56 with JSONObject

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

the class JSONObjectTest_get_2 method test_get_obj.

public void test_get_obj() throws Exception {
    JSONObject obj = new JSONObject();
    {
        Map<String, Object> value = new HashMap<String, Object>();
        value.put("@type", "com.alibaba.json.bvt.JSONObjectTest_get_2$VO");
        value.put("id", 1001);
        obj.put("value", value);
    }
    VO value = (VO) obj.getObject("value", Object.class);
    Assert.assertEquals(1001, value.getId());
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) Map(java.util.Map) HashMap(java.util.HashMap)

Example 57 with JSONObject

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

the class MaterializedInterfaceTest2 method test_parse.

public void test_parse() throws Exception {
    String text = "{\"id\":123, \"name\":\"chris\"}";
    JSONObject object = JSON.parseObject(text);
    Bean bean = TypeUtils.cast(object, Bean.class, null);
    Assert.assertEquals(123, bean.getId());
    Assert.assertEquals("chris", bean.getName());
    String text2 = JSON.toJSONString(bean);
    System.out.println(text2);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 58 with JSONObject

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

the class JSONObjectTest5 method test.

public void test() throws Exception {
    JSONObject jsonObject = new JSONObject(3, true);
    jsonObject.put("name", "J.K.SAGE");
    jsonObject.put("age", 21);
    jsonObject.put("msg", "Hello!");
    JSONObject cloneObject = (JSONObject) jsonObject.clone();
    assertEquals(JSON.toJSONString(jsonObject), JSON.toJSONString(cloneObject));
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 59 with JSONObject

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

the class JSONObjectTest6 method test.

public void test() throws Exception {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("value", 123);
    Model model = jsonObject.toJavaObject(Model.class);
    assertEquals(123, model.value);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 60 with JSONObject

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

the class Bug_for_gongwenhua method test_0.

public void test_0() throws Exception {
    String text = "{\"FH2\\\"\\v\":0,\"alipa9_login\":0,\"alipay_login\":14164,\"durex\":317,\"intl.datasky\":0,\"taobao_refund\":880}";
    JSONObject obj = JSONObject.parseObject(text);
    Assert.assertNotNull(obj);
    Assert.assertEquals(0, obj.get("FH2\""));
}
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