将json转换为jsonp格式
来源:互联网 发布:网络层次结构 编辑:程序博客网 时间:2024/05/16 06:29
private static final String JAVASCRIPT_TYPE = "text/javascript";
ObjectMapper mapper = new ObjectMapper();
String jsonString = null;
try {jsonString = mapper.writeValueAsString(object);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
String result = new StringBuilder().append(callbackName).append("(").append(jsonString).append(");").toString();
// 渲染Content-Type为javascript的返回内容,输出结果为javascript语句, 如callback197("{html:'Hello World!!!'}");
render(JAVASCRIPT_TYPE, result, headers);
/**
* 直接输出内容的简便函数.
*
* eg. render("text/plain", "hello", "encoding:GBK");
* render("text/plain", "hello", "no-cache:false");
* render("text/plain", "hello", "encoding:GBK", "no-cache:false");
*
* @param contentType
* String 数据报
* @param content
* String 数据内容
* @param headers
* String... 可变的header数组,目前接受的值为"encoding:"或"no-cache:",默认值分别为UTF-8和true.
*/
public static void render(final String contentType, final String content, final String... headers) {
HttpServletResponse response = initResponse(contentType, headers);
PrintWriter out = null;
try {
out = response.getWriter();
out.write(content);
out.flush();
out.close();
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
- 将json转换为jsonp格式
- 将数组转换为json格式字符串
- android将对象转换为json格式
- 将数据转换为json格式代码
- JSON.parse将字符串转换为JSON格式
- JSONObject转换JSON--将Date转换为指定格式
- JSONObject转换JSON--将Date转换为指定格式
- JSONObject转换JSON--将Date转换为指定格式
- JSONObject转换JSON--将Date转换为指定格式
- JSONObject转换JSON--将Date转换为指定格式
- JSONObject转换JSON--将Date转换为指定格式
- JSONObject转换JSON--将Date转换为指定格式
- C#将对象转换为xml或json格式
- 将任意格式转换为JSON数据格式的工具类
- asp.net将类实例转换为JSON格式
- 将任意格式转换为JSON数据格式的工具类
- 将java对象转换为Json格式字符串
- <项目一>怎么将数据转换为json格式
- Dom模型之dataset属性/Html元素标签的data-*属性
- 关于安卓 模块内的manifest文件使用占位符的思考
- CodeForces 287 D.Shifting(机智)
- fedora重新build rpm软件安装包
- 刚哥遇到了感情问题
- 将json转换为jsonp格式
- 【笔记】正则表达式中/g的含义
- 线程池的原理及实现(1)
- 文章标题 HDU 3530 : Subsequence(单调队列)
- netty私有协议的开发
- 深入理解Java:注解(Annotation)自定义注解入门
- JAVA中多线程笔记总结
- 为项目设置小图标
- bootstrap的table表格使用