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);
}
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]);
}
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]);
}
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));
}
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());
}
Aggregations