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, SerializerFeature.MapSortField);
assertEquals("/**/parent.callback({\"id\":1,\"name\":\"ido\\u0029nans\"},1,2)", json);
}
use of com.alibaba.fastjson.JSONPObject in project e3mall by colg-cloud.
the class TokenController method getUserByToken.
/**
* 根据token获取user信息
*
* 使用 fastjson JSONPObject对象处理
*
* @param token
* @param callback
* 跨域请求
* @return
*/
@GetMapping(value = "/user/{token}")
public Object getUserByToken(@PathVariable String token, String callback) {
E3Result e3Result = tokenService.getUserByToken(token);
// 响应结果之前,判断是否为jsonp请求, jsonp会自动带 callback
if (StringUtils.isNotBlank(callback)) {
// 创建jsonp对象
JSONPObject jsonpObject = new JSONPObject(callback);
jsonpObject.addParameter(e3Result);
return jsonpObject;
}
return e3Result;
}
Aggregations