Search in sources :

Example 76 with JSONObject

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

the class Issue177 method test_for_issue_177.

public void test_for_issue_177() throws Exception {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("data", new byte[20]);
    String jsonString = JSON.toJSONString(jsonObject);
    JSONObject parseObject = JSON.parseObject(jsonString);
    byte[] bytes = parseObject.getBytes("data");
    byte[] bs = parseObject.getObject("data", byte[].class);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 77 with JSONObject

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

the class Issue179 method test_for_issue_179.

public void test_for_issue_179() throws Exception {
    Student student = new Student();
    School school = new School();
    school.setStudent(student);
    student.setSchool(school);
    // String schoolJSONString = JSON.toJSONString(school);
    // System.out.println(schoolJSONString);
    //
    // School fromJSONSchool = JSON.parseObject(schoolJSONString,
    // School.class);
    //
    // System.out.println(JSON.toJSONString(fromJSONSchool));
    JSONObject object = new JSONObject();
    object.put("school", school);
    String jsonString = JSON.toJSONString(object);
    System.out.println(jsonString);
    JSONObject object2 = (JSONObject) JSON.parseObject(jsonString, JSONObject.class);
    System.out.println(JSON.toJSONString(object2));
    School school2 = object2.getObject("school", School.class);
    System.out.println(school2);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject)

Example 78 with JSONObject

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

the class Bug_for_liuying method test_for_bug.

public void test_for_bug() throws Exception {
    String aa = "[{\"dictFont\":\"\",\"dictId\":\"wap\",\"dictName\":\"无线&手淘\"},{\"dictFont\":\"\",\"dictId\":\"etao\",\"dictName\":\"搜索\"}]";
    JSONObject jsonResult = new JSONObject();
    JSONArray jsonArray = JSONArray.parseArray(aa);
    jsonResult.put("aaa", jsonArray);
    System.out.println(jsonResult);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray)

Example 79 with JSONObject

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

the class Bug_for_sanxiao method test_0.

public void test_0() throws Exception {
    InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/Bug_for_sanxiao.json");
    String text = IOUtils.toString(is);
    is.close();
    JSONObject obj = JSON.parseObject(text);
    System.out.println(obj);
    Assert.assertEquals(obj.getJSONArray("segments").getJSONObject(0), obj.getJSONArray("passengerSegmentItems").getJSONObject(0).get("segment"));
    Assert.assertEquals(1428, obj.getJSONArray("passengerSegmentItems").getJSONObject(0).getJSONObject("segment").getIntValue("agentId"));
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) InputStream(java.io.InputStream)

Example 80 with JSONObject

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

the class Bug_for_issue_446 method test_for_issue.

public void test_for_issue() throws Exception {
    String text = "{\"amount\":1,\"channel_id\":\"wnys01\",\"gem\":1,\"id\":\"pay\",\"login_name\":\"U10722466A\",\"money\":1000,\"order_id\":\"99142AO10000086695A\",\"pay_channel\":\"weilan\",\"pay_time\":\"2015-11-05 20:59:04\",\"reward\":\"11:5_12:5_13:5,4:1_5:1_6:1\",\"status\":1,\"user_id\":19313}";
    JSONObject obj = (JSONObject) JSON.parse(text);
    Assert.assertEquals(1, obj.get("amount"));
}
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