java 返回 JSON给JS

JAVA:json

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

JS:app

//这个response是回调参数
response =	JSON.stringify(response);//将对象转换为JSON字符串,这时候能够直接打印
response = JSON.parse(response); //将JSON字符串解析为JSON对象
console.log('decodeContent:'+response.decodeContent);//打印对象指定key的value
相关文章
相关标签/搜索