Search in sources :

Example 71 with JSONObject

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

the class Issue1063 method test_for_issue.

public void test_for_issue() throws Exception {
    long currentMillis = System.currentTimeMillis();
    TimestampBean bean = new TimestampBean();
    bean.setTimestamp(new Timestamp(currentMillis));
    String timestampJson = JSON.toJSONString(bean);
    // 这里能转换成功
    TimestampBean beanOfJSON = JSON.parseObject(timestampJson, TimestampBean.class);
    // 这里抛异常 java.lang.NumberFormatException
    JSONObject jsonObject = JSON.parseObject(timestampJson);
    Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
    assertEquals(currentMillis / 1000, timestamp2.getTime() / 1000);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) Timestamp(java.sql.Timestamp)

Example 72 with JSONObject

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

the class Issue125 method test_for_issue.

public void test_for_issue() throws Exception {
    String content = "{\"data\":\"sfasfasdfasdfas\\r" + String.valueOf((char) 160) + "\\rasdfasdfasd\"}";
    JSONObject jsonObject = JSON.parseObject(content);
    System.out.println(jsonObject);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 73 with JSONObject

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

the class Issue126 method test_for_issue.

public void test_for_issue() throws Exception {
    JSONObject j = new JSONObject();
    j.put("content", "爸爸去哪儿-第十期-萌娃比赛小猪快跑 爸爸上演\"百变大咖秀\"-【湖南卫视官方版1080P】20131213: http://youtu.be/ajvaXKAduJ4  via @youtube");
    System.out.println(j.toJSONString());
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 74 with JSONObject

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

the class Bug_for_jiangwei1 method test_double.

public void test_double() throws Exception {
    JSONObject json = JSON.parseObject("{\"val\":12.3}");
    Assert.assertTrue(12.3D == json.getDoubleValue("val"));
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 75 with JSONObject

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

the class Issue157 method test_for_issue.

public void test_for_issue() throws Exception {
    String m = "2、95开头靓号,呼出显号,对方可以打回,即使不在线亦可设置呼转手机,不错过任何重要电话,不暴露真实身份。\r\n3、应用内完全免费发送文字消息、语音对讲。\r\n4、建议WIFI 或 3G 环境下使用以获得最佳通话体验";
    JSONObject json = new JSONObject();
    json.put("介绍", m);
    String content = json.toJSONString();
    System.out.println(content);
}
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