您的位置:首页 > 编程语言 > Java开发

java 返回 JSON给JS

2016-04-06 00:00 507 查看
JAVA:

JSONObject	json	=	new	JSONObject();
json.append("decodeContent", decodeContent);//decodeContent在我这里是个字符串,append(String key, object value);
out.println(json.toString());
//或者输出字符串
out.println("{\"decodeContent\":\""+decodeContent+"\"}");

JS:

//这个response是回调参数
response =	JSON.stringify(response);//将对象转换为JSON字符串,这时候可以直接打印
response = JSON.parse(response); //将JSON字符串解析为JSON对象
console.log('decodeContent:'+response.decodeContent);//打印对象指定key的value
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Java JSON js