【求助】C#写的WebService,连接数据库后如何返回JSON字符串??
我现在的问题是,数据库能用WebService连接成功,而且能返回数据。但是,我想返回JSON形式的数据,我现在得到的返回形式是XML。
如下图所示:

以上图片是我现在得到的返回形式。

以上图片是我期望得到的返回形式。
以上是我的代码。
求教大神我如何修改代码。如果有详细的教程,也可以发给我。网上有好多没用的教程。
如下图所示:

以上图片是我现在得到的返回形式。

以上图片是我期望得到的返回形式。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
[System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
static String strCon = "Data Source=WZY-PC;Initial Catalog=DB_Haier;Integrated Security=True";
public Service () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod(Description = "返回数据测试")]
public DataSet TestReturn()
{
SqlConnection con = new SqlConnection();
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "select * from TB_Admin";
SqlDataAdapter da = new SqlDataAdapter(cmd.CommandText,strCon);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
}以上是我的代码。
求教大神我如何修改代码。如果有详细的教程,也可以发给我。网上有好多没用的教程。
...全文
相关推荐
动态调取webservice返回json数据并处理
动态调取webservice返回json数据,并把数据绑定到gridview中
C# WebService 客户端 服务器 Json
C# WebService 客户端 服务器 Json;C# WebService 客户端 服务器 Json
C#开发webservice接口,对客户端post服务的Json数据进行接收反馈
C#开发webservice接口,对客户端post服务的Json数据进行接收反馈 接收到的数据流转换成string类型,有其他需求对json解析,自己写个解析去查询下. 然后反馈json发送给请求端。
C#后台返回json类型数据
只需要将dt传过来就能够生成json类型数据
C#开发WebService
开发Android应用,需要服务器,很多人采用Java发布XML或JSON,本人对Java了解不多,所以采用.net开发WebService发布XML或者JSON


Web Services
