Search in sources :

Example 86 with JSONObject

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

the class Issue_for_oschina_3087749_2215732 method test_for_issue.

public void test_for_issue() throws Exception {
    String json = "{\"datas\":[\"a\",\"b\"]}";
    JSONObject o = JSON.parseObject(json);
    o.toJavaObject(JsonBean.class);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 87 with JSONObject

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

the class Issue248_orderedField method test_3.

public void test_3() throws Exception {
    String text = "{\"k1\":\"v1\",\"k3\":\"v3\",\"k2\":\"v2\",\"list\":[\"v1\",\"v3\",\"v2\",{\"map\":{\"k1\":\"v1\",\"k3\":\"v3\",\"k2\":\"v2\"}}]}";
    System.out.println(JSON.parseObject(text));
    JSONObject object = JSON.parseObject(text, Feature.OrderedField);
    System.out.println(object);
    Assert.assertEquals("k1", object.keySet().toArray()[0]);
    Assert.assertEquals("k3", object.keySet().toArray()[1]);
    Assert.assertEquals("k2", object.keySet().toArray()[2]);
    Assert.assertEquals("list", object.keySet().toArray()[3]);
    Assert.assertEquals("k1", object.getJSONArray("list").getJSONObject(3).getJSONObject("map").keySet().toArray()[0]);
    Assert.assertEquals("k3", object.getJSONArray("list").getJSONObject(3).getJSONObject("map").keySet().toArray()[1]);
    Assert.assertEquals("k2", object.getJSONArray("list").getJSONObject(3).getJSONObject("map").keySet().toArray()[2]);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 88 with JSONObject

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

the class Issue248_orderedField method test_2.

public void test_2() throws Exception {
    String text = "{\"k1\":\"v1\",\"k3\":\"v3\",\"k2\":\"v2\",\"map\":{\"k1\":\"v1\",\"k3\":\"v3\",\"k2\":\"v2\",\"map\":{\"k1\":\"v1\",\"k3\":\"v3\",\"k2\":\"v2\"}}}";
    System.out.println(JSON.parseObject(text));
    JSONObject object = JSON.parseObject(text, Feature.OrderedField);
    System.out.println(object);
    Assert.assertEquals("k1", object.keySet().toArray()[0]);
    Assert.assertEquals("k3", object.keySet().toArray()[1]);
    Assert.assertEquals("k2", object.keySet().toArray()[2]);
    Assert.assertEquals("map", object.keySet().toArray()[3]);
    Assert.assertEquals("k1", object.getJSONObject("map").keySet().toArray()[0]);
    Assert.assertEquals("k3", object.getJSONObject("map").keySet().toArray()[1]);
    Assert.assertEquals("k2", object.getJSONObject("map").keySet().toArray()[2]);
    Assert.assertEquals("map", object.getJSONObject("map").keySet().toArray()[3]);
    Assert.assertEquals("k1", object.getJSONObject("map").getJSONObject("map").keySet().toArray()[0]);
    Assert.assertEquals("k3", object.getJSONObject("map").getJSONObject("map").keySet().toArray()[1]);
    Assert.assertEquals("k2", object.getJSONObject("map").getJSONObject("map").keySet().toArray()[2]);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 89 with JSONObject

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

the class Issue743 method test_for_issue.

public void test_for_issue() throws Exception {
    String temp = "{\"option_1\": \"\\u4e0d\\u5403\\u6216\\u5c11\\u4e8e1\\u6b21\"}";
    JSONObject object = JSON.parseObject(temp);
    Assert.assertEquals("{\"option_1\":\"不吃或少于1次\"}", JSON.toJSONString(object));
    Assert.assertEquals("{\"option_1\":\"\\u4E0D\\u5403\\u6216\\u5C11\\u4E8E1\\u6B21\"}", JSON.toJSONString(object, SerializerFeature.BrowserCompatible));
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 90 with JSONObject

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

the class DateTest_dotnet_5 method test_date.

public void test_date() throws Exception {
    String text = "{\"date\":\"/Date(1461081600321)/\"}";
    JSONObject model = JSON.parseObject(text);
    Assert.assertEquals(1461081600321L, ((java.util.Date) model.getObject("date", java.util.Date.class)).getTime());
}
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