.net 接口返回json格式示例

1、新建 InterfaceTestPro1 项目:

FILE - New - Project... - Web - ASP.NET Web Forms Application

name:InterfaceTestPro1

2、新建 test.ashx 项:

项目右键 - Add - New Item.... - Generic Handler

name:test.ashx

将 ProcessRequest 方法替换成如下代码

            context.Response.ContentType = "text/plain";
            RspMsg rspMsg = new RspMsg();
            string name = context.Request.Form["name"].ToString();
            rspMsg.ReturnCode = "1";
            rspMsg.ReturnMessage = "Welcome " + name;
            context.Response.Write(rspMsg.ToString());

3、新建 test.html 项:

项目右键 - Add - New Item.... - HTML Page

name:test.html

代码如下

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <form name="form1" method="post" action="test.ashx">
        name:  <input type="text" name="name" value=""/>
        <input type="submit" value="submit"/>
    </form>
</body>
</html>

4、效果演示:

提交

右键查看源码

 

posted on 2016-01-18 14:45  Xw_hacker  阅读(1506)  评论(0编辑  收藏  举报

导航