ASP输出JSON格式

菜鸟看虾 2014-01-05 08:31:26
json.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<%
username="tom"
sex="男"
age="18"
response.write "姓名:"+username +"<br/>"+"性别:"+sex +"<br/>"+"年龄:"+age
%>
</body>
</html>

这段asp代码能够正常输入结果,请问如何将这结果以json的格式输出呢
因为我要用ajax调用json格式的,现在不明白,谢谢
...全文
659 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Hello World, 2014-01-09
  • 打赏
  • 举报
回复
引用 2 楼 u013280765 的回复:
[quote=引用 1 楼 apollokk 的回复:] response.write "{""姓名"":" & username & ",""性别"":" & sex & ",""年龄"":" & age & "}"
你好,我用asp输入上面的结果 然后用ajax怎么都得不到结果的呢,用别的json能够得到结果,要不要还要有别的什么啊,麻烦在帮我看下,谢谢 ajax代码

$(function (){
	 $.ajax({
		 url:"json.asp",
		 dataType:'json',
		 async:true, 
		 type:'get',
		 success:function(data){
		   alert(data.a);
		 },
		 error:function(XMLHttpRequest, textStatus, errorThrown) {
		   alert(errorThrown);
		 }});
})
json.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Response.Charset = "UTF-8" %>
<%
username="tom"
sex="男"
age="18"
'response.write "姓名:"+username +"<br/>"+"性别:"+sex +"<br/>"+"年龄:"+age
response.write "{""a"":" & username & ",""b"":" & sex & ",""c"":" & age & "}"
%>
[/quote] dataType:'json'时需要设置输出类型,如果不设置得到字符串后再解析也可以
Dogfish 2014-01-07
  • 打赏
  • 举报
回复
也可以参考这个,这是一个别人写好的class来的 http://demon.tw/my-work/vbs-json.html
宁静志远 2014-01-06
  • 打赏
  • 举报
回复
把json,asp里输出json的句改为:response.write "{""a"":""" & username & """,""b"":""" & sex & """,""c"":""" & age & """}"
Anlige 2014-01-06
  • 打赏
  • 举报
回复
http://www.9fn.net/post/34.html 参考~
菜鸟看虾 2014-01-05
  • 打赏
  • 举报
回复
引用 1 楼 apollokk 的回复:
response.write "{""姓名"":" & username & ",""性别"":" & sex & ",""年龄"":" & age & "}"
你好,我用asp输入上面的结果 然后用ajax怎么都得不到结果的呢,用别的json能够得到结果,要不要还要有别的什么啊,麻烦在帮我看下,谢谢 ajax代码

$(function (){
	 $.ajax({
		 url:"json.asp",
		 dataType:'json',
		 async:true, 
		 type:'get',
		 success:function(data){
		   alert(data.a);
		 },
		 error:function(XMLHttpRequest, textStatus, errorThrown) {
		   alert(errorThrown);
		 }});
})
json.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Response.Charset = "UTF-8" %>
<%
username="tom"
sex="男"
age="18"
'response.write "姓名:"+username +"<br/>"+"性别:"+sex +"<br/>"+"年龄:"+age
response.write "{""a"":" & username & ",""b"":" & sex & ",""c"":" & age & "}"
%>
Hello World, 2014-01-05
  • 打赏
  • 举报
回复
response.write "{""姓名"":" & username & ",""性别"":" & sex & ",""年龄"":" & age & "}"

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧