Search in sources :

Example 6 with JSONPObject

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

the class JSONPParseTest3 method test_f.

public void test_f() throws Exception {
    String text = "parent.callback ({'id':1, 'name':'ido)nans'},1,2 );   /**/ ";
    JSONPObject jsonpObject = (JSONPObject) JSON.parseObject(text, JSONPObject.class);
    assertEquals("parent.callback", jsonpObject.getFunction());
    assertEquals(3, jsonpObject.getParameters().size());
    JSONObject param = (JSONObject) jsonpObject.getParameters().get(0);
    assertEquals(1, param.get("id"));
    assertEquals("ido)nans", param.get("name"));
    String json = JSON.toJSONString(jsonpObject, SerializerFeature.BrowserSecure);
    assertEquals("/**/parent.callback({\"name\":\"ido\\u0029nans\",\"id\":1},1,2)", json);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONPObject(com.alibaba.fastjson.JSONPObject)

Example 7 with JSONPObject

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

the class JSONPObjectTest method test_jsonp_1.

public void test_jsonp_1() throws Exception {
    JSONPObject jsonp = new JSONPObject();
    jsonp.setFunction("checkValid");
    jsonp.addParameter(new HashMap<String, Object>());
    jsonp.addParameter(new ArrayList<Object>());
    Assert.assertEquals("checkValid", jsonp.getFunction());
    Assert.assertEquals(2, jsonp.getParameters().size());
    String text = jsonp.toString();
    Assert.assertEquals("checkValid({},[])", text);
    Assert.assertEquals("checkValid({},[])", jsonp.toJSONString());
}
Also used : JSONPObject(com.alibaba.fastjson.JSONPObject) JSONPObject(com.alibaba.fastjson.JSONPObject)

Aggregations

JSONPObject (com.alibaba.fastjson.JSONPObject)7 JSONObject (com.alibaba.fastjson.JSONObject)4 JSONException (com.alibaba.fastjson.JSONException)1