ASP.NET WebService Response.Write乱码解决
2017-10-23 10:22
387 查看
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using Utility; using System.Data; using System.Text; namespace Service { /// <summary> /// api 的摘要说明 /// </summary> [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 api : System.Web.Services.WebService { [WebMethod] public void Search(string param) { string json = "[]"; string SQL = string.Format("SELECT * FROM tbl_dnvod_video WHERE Title LIKE '%{0}%'", param); DataTable dt = SQLHelper.ExcuteSQL(SQL); if (dt != null && dt.Rows.Count > 0) { json = JsonHelper.DataTableToJson(dt); } HttpContext.Current.Response.Write(json); //中文出现乱码是因为使用了Encoding.UTF8等字符编码,使用Encoding.GetEncoding("GB2312")即可解决乱码问题 HttpContext.Current.Response.ContentEncoding = Encoding.GetEncoding("GB2312"); HttpContext.Current.Response.End(); } } }
相关文章推荐
- ASP.NET:UpdatePanel与Response.Write()不兼容解决方法
- ASP.NET response.write alert后 导致页面布局改变的解决方法
- wp7使用POST请求Asp.net网页时,HttpWebRequest的BeginGetResponse方法抛出NotSupportException异常的解决方法
- C# ASP.NET Webservice调用外部exe无效的解决方法
- 【转】彻底解决Asp.net文件下载(Response.WriteFile)时文件名的中文乱码和空格异常问题
- C# ASP.NET Webservice调用外部exe无效的解决方法
- asp.net web页传参数为汉字时,会失败,有些汉字会变成乱码,解决方法如下:
- Asp.net 2.0 Request ,Response 出现乱码 Email乱码 解决方法
- asp.net中使用response.write造成界面变形问题的解决办法
- C# ASP.NET Webservice调用外部exe无效的解决方法
- ASP.NET一般处理程序新建一个方法里使用context.Response.Write的解决方法
- ASP.NET中使用 Response.Write("<script>alert('****');</script>");后CSS界面发生变化的解决方法 (经验证)
- asp.net中URL参数传值中文乱码的三种解决办法
- IIS Web服务扩展中没有Asp.net 2.0解决方法
- ASP:如何解决Response.Redirect方法传递汉字丢失或乱码问题?
- Virus Scanner induced bug with ASP.NET webservice application
- .NET 调用java webservice保存datetime类型数据为空的解决办法
- Asp.net中Mysql存储中文乱码解决方法
- ASP.NET中文乱码问题解决
- asp.net无法在Web服务器上启动调试项目的解决办法