专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Web Service

getJson 访问JSON在服务器上访问值是乱码,在本机上回来确实OK的,求大神指教

发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
getJson 访问JSON在服务器上访问值是乱码,在本机上返回确实OK的,求大神指教
前台页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <script src="http://shdesign.soufun.com/js/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
        var S_Fj=jQuery.noConflict();

        S_Fj(document).ready(function() {
         // var clientUrl = "http://localhost:4508/WebService.asmx/HelloWorld?jsoncallback=?";
            var clientUrl = "http://shdesign.soufun.com/huyong/m/WebService/WebService1.asmx/HelloWorld?jsoncallback=?";
            var currentCity = "哈尔滨";
            S_Fj.getJSON(
                clientUrl,
                { city: currentCity },
                function (json) {

                    S_Fj("#data").html("城市:" +json.city + ",时间:" + json.dateTime);
                }
            );
        });
        function OnSuccess(responseData) {
            S_Fj("#data").html(responseData.city);
        }
        function OnError(XMLHttpRequest, textStatus, errorThrown) {
            targetDiv = S_Fj("#data");
            if (errorThrown || textStatus == "error" || textStatus == "parsererror" || textStatus == "notmodified") {
                targetDiv.replaceWith("请求数据时发生错误!");
                return;
            }
            if (textStatus == "timeout") {
                targetDiv.replaceWith("请求数据超时!");
                return;
            }
        }
    </script>
</head>
<body>
<div id="data"></div>
</body>
</html>

访问wbservices端代码

   
        public void HelloWorld(string city)  
        {  
            string callbackMethodName = HttpContext.Current.Request.Params ?? "";  
            city = string.IsNullOrEmpty(city) ? "北京" : "沈阳";  
            string result = callbackMethodName + "({"city":" + """ + HttpUtility.UrlDecode(city) + "", "dateTime":" + """ + DateTime.Now + ""});";
         
            HttpContext.Current.Response.Write(result);  
            HttpContext.Current.Response.End();  
        }

本机上返回结果


城市:沈阳,时间:2013-12-27 11:00:46

服务器返回结果

({"city":"娌堥槼", "dateTime":"2013-12-27 11:03:04"});


请大神指教
------解决方案--------------------
HttpUtility.UrlDecode(city,Encoding.GetEncode(gb2312))
  
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/
------解决方案--------------------
http://www.2cto.com/kf/201211/167268.html
------解决方案--------------------
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: