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; }
    }
  • 相关阅读:
    文件处理
    字符编码的了解以及简单的文件处理
    python list去重加set排序
    数据的类型以及内置方法
    Python 入门 Day5
    Python 入门 Day3
    Python的入门
    计算机硬件
    【0903 | Day 29】反射和内置方法
    【0902 | Day 28】绑定方法和非绑定方法
  • 原文地址:https://www.cnblogs.com/jake-ge/p/4721550.html
Copyright © 2011-2022 走看看