Android中从SQL数据库检索数据的最佳方法
我在使用Asp.NETWebService使用SOAP方法从Android应用程序中的SQL数据库检索数据。 我也见过JSON方法,但它使用的是php。Android中从SQL数据库检索数据的最佳方法,android,asp.net,sql,web-services,Android,Asp.net,Sql,Web Services,我在使用Asp.NETWebService使用SOAP方法从Android应用程序中的SQL数据库检索数据。 我也见过JSON方法,但它使用的是php。 哪种方法最好???我有Windows Server和SQL数据库,所以我只使用Asp.NET web服务。如果你有SQL Server,意味着你可以使用Asp.NET Json web服务。Json非常容易解析,我自己也只使用Json格式的.NETWebService 解析对于移动开发人员来说既快又容易 public class Employe
哪种方法最好???我有Windows Server和SQL数据库,所以我只使用Asp.NET web服务。如果你有SQL Server,意味着你可以使用Asp.NET Json web服务。Json非常容易解析,我自己也只使用Json格式的.NETWebService 解析对于移动开发人员来说既快又容易
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数组对象
[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新手。你使用这个URL。在哪里传递查询来检索数据?你能给我一些实时示例吗?我将第一次使用它,所以我无法理解它。伙计,我给了你我的现场网站的示例代码。。首先,你要从数据库中检索一个通用列表。然后使用我的web服务。要获得数据库列表作为一个通用的你有很多选择,伙计。。