zoukankan      html  css  js  c++  java
  • android--asp.net webservice 返回json

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Web.Script.Services;
    using System.Web.Script.Serialization;
    
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.Web.Script.Services.ScriptService]
    
    public class Service : System.Web.Services.WebService
    {
        public Service () {}
        
        [WebMethod]
        [ScriptMethod(ResponseFormat=ResponseFormat.Json)]
        public string Authenticate(string UserId, string UserPwd)
        {
            bool result = true;
            return new JavaScriptSerializer().Serialize(result);
        }
    
        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string GetUser()
        {
            User user = new User();
            user.UserId = "jake";
            user.UserPwd = "123";
            return new JavaScriptSerializer().Serialize(user);
        }
    
        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string GetUsers()
        {
            List<User> list = new List<User>();
            User user = new User();
            user.UserId = "jake";
            user.UserPwd = "123";
            list.Add(user);
            user.UserId = "nola";
            user.UserPwd = "456";
            list.Add(user);
            return new JavaScriptSerializer().Serialize(list);
        }
    }
    
    public class User
    {
        public string UserId { get; set; }
        public string UserPwd { get; set; }
    }
  • 相关阅读:
    [SUCTF 2019]EasySQL
    [强网杯 2019]随便注
    [HCTF 2018]WarmUp
    Linux下配置JDK环境
    Centos克隆虚拟机后配置网络
    Sublime安装插件
    LeetCode-91-解码方法
    LeetCode-322-零钱兑换
    LeetCode-152-乘积最大子数组
    LeetCode-139-单词拆分
  • 原文地址:https://www.cnblogs.com/jake-ge/p/4721550.html
Copyright © 2011-2022 走看看