前台如何解析json格式 以及后台如何生成json格式

前台:

   $.ajax({
                type: "POST",

                url: "GetMenuRole.ashx",
                data: "",
                dataType: "json",
                success: function (data) {

                    if (data.Status == false) {
                        alert(data.ErrorReason);
                    }
                    else {
                        //解析这个菜单列表

                        alert(data.MenuList);

                    }

                },
                error: function (data) {
                    alert(data);
                }

            });

后台:(需要使用双引号)

  string sReturnJson = " <KH>\"Status\":\"{0}\",\"MenuList\":\"{1}\",\"ErrorReason\":\"{2}\"</KH>";

 sReturnJson = string.Format(sReturnJson, "True", sReturnMenuList,string.Empty).Replace("<KH>","{").Replace("</KH>","}");
                context.Response.Write(sReturnJson);

posted @ 2011-07-05 14:40  郑文亮  阅读(1926)  评论(0编辑  收藏  举报