【问题标题】:Best method to retrive data from SQL DB in Android在 Android 中从 SQL DB 检索数据的最佳方法
【发布时间】:2014-01-20 09:03:48
【问题描述】:

我正在使用 SOAP 方法使用 Asp.NET Webservice 从 Android 应用程序中的 SQL 数据库中检索数据。
我也见过 JSON 方法,但它使用的是 php。

哪种方法最好???我有 Windows Server 和 SQL 数据库,所以我将只使用 Asp.NET Web 服务。

【问题讨论】:

    标签: android asp.net sql web-services


    【解决方案1】:

    如果你有 SqlServer 意味着你可以选择 asp.Net Json Webservices 。 Json 很容易解析,我自己也只使用 json 格式的 .net 网络服务。

    解析对移动开发者来说既快速又简单

    public class Employee
    {
        public string Name { get; set; }
        public string Company { get; set; }
        public string Address { get; set; }
        public string Phone { get; set; }
        public string Country { get; set; }
    }
    

    然后在 Webserice 中添加以下方法。

    Json Array-Object大部分我们会使用

         [WebMethod]
         [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
         public static string GenerateTopicListToJSon()
                {
                    try
    
                    {
    
                        //Do ur query in GetMethod() to retrieve from DB     
                        List<Employee> lstEmployee = GetMethod();
                        var topic = from t in lstEmployee
                                    select new
                                    {
                                        Name= t.TopicID,
                                        Company = t.Company,
                                        Address = t.Address,
                            Phone = t.Phone,
                                        Country = t.Country
    
                                    };
    
    
                        var oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                        return oSerializer.Serialize(topic);
    
                    }
    

    希望对你有帮助..

    干杯。

    【讨论】:

    • 感谢您的回复。你能给我一些示例代码吗,因为我是 Android 新手。
    • 在哪里传递查询来检索数据?
    • 你能给我任何实时的例子吗?我是第一次用,看不懂。
    • 伙计,我给了你我现场网站上的示例代码。首先你要从 db 作为通用列表检索。然后使用我的网络服务。要将数据库列表作为通用列表,您有很多选择,伙计..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多