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; }
    }
  • 相关阅读:
    [Nowcoder]2020牛客寒假算法基础集训营3
    [Nowcoder]2020牛客寒假算法基础集训营2
    [Nowcoder]2020牛客寒假算法基础集训营1
    [备份]算法模板大集锦
    [东西]neverOpen
    [随笔]ICPC2.0
    [知识点]C++中STL容器之set
    [知识点]数列分块入门1-9
    [知识点]C++中STL容器之vector
    [知识点] 1.3.1 STL简介
  • 原文地址:https://www.cnblogs.com/jake-ge/p/4721550.html
Copyright © 2011-2022 走看看