ASP.NET WebService Response.Write乱码解决
ASP.NET WebService Response.Write乱码解决
http://blog.csdn.net/qq285679784/article/details/78316094
- 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();
- }
- }
- }
版权声明:本文为博主原创文章,只为分享而编,欢迎各位学习以及转载。 http://blog.csdn.net/qq285679784/article/details/78316094

浙公网安备 33010602011771号