關於webservice返回json

來源:互聯網
上載者:User

標籤:des   style   blog   ar   io   color   os   sp   for   

 [WebMethod]        public List<PictureManager> LoadPictureOne()        {            dataDataContext context = new dataDataContext();            List<PictureManager> list = new List<PictureManager>();            try            {                List<PictureManager> li = context.PictureManager.Where(p => p.TypeId == 2 && p.IsShow == true).OrderByDescending(p => p.Id).Take(8).ToList();                foreach (PictureManager item in li)                {                    PictureManager tb = new PictureManager();                    tb.Id = item.Id;                    tb.Name = item.Name;                    tb.Picture = item.Picture;                    tb.Price = item.Price;                    tb.PriceInfo = item.PriceInfo;                    tb.Remark = item.Remark;                    list.Add(tb);                }            }            catch (Exception ex)            {                throw new Exception(ex.Message);            }            return list;        }
//載入圖片1function LoadPictureOne() {    $("#div1").html("");    var htmlInfo = "";    $.ajax({        type: "post",        contentType: "application/json;charset=utf-8",        url: "../../service/backstageService.asmx/LoadPictureOne",        data: "",        dataType: "json",        success: function (result) {            var data = eval(result.d);            $(data).each(function () {                htmlInfo += "<div class=‘moxin‘><div ><img style=\"width:223px; height:217px;\" src=‘../../images/PictureManager/" + this.Picture + "‘ alt=‘" + this.Name + "‘ /></div><ul><li><p class=‘wenziqj‘>" + this.Price + "</p></li><li><p class=‘wenzish‘> " + this.PriceInfo + "</p><p class=‘wenzixia‘>" + this.Name + "</p></li><li class=‘tuliji‘   onclick=‘img_click(\"" + this.Name + "\")‘><img src=‘../../images/images/qiangoguanniu.png‘ style=‘cursor:pointer‘ /></li></ul></div>";            });            $("#div1").html($.trim(htmlInfo));        },        error: function (err) { layer.alert("載入圖片出錯", 5); }    });}

 如果返回的 是單個對象:
 result.d的值是:"{"brxm":"aa","ys":"bb","ks":"cc","hm":"123","sj":"08:50"}"
eval("("+result.d+")")試一試。

     [WebMethod]        public string GetCount()        {            string json = string.Empty;            try            {                using (dataDataContext context = new dataDataContext())                {                    if (context.tb_ApplicationAward.Count() != 0)                    {                        int CountM = Convert.ToInt32(context.tb_ApplicationAward.Sum<tb_ApplicationAward>(p => p.scheduleLength));                        if (CountM > 2000)                        {                            CountM = 2000;                        }                        int CountPeople = context.tb_ApplicationAward.Count();                        return "{‘CountM‘:" + CountM + ",‘CountPeople‘:" + CountPeople + "}";                    }                    return "{\"CountM\":" + 0 + ",\"CountPeople\":" + 0 + "}";                }            }            catch (Exception)            {                return null;            }        }
function Loading() {    $.ajax({        type: "post",        contentType: "application/json;charset=utf-8",        url: "../../service/backstageService.asmx/GetCount",        data: "{}",        dataType: "json",        success: function (js) {            var obj = eval(‘(‘ + js.d + ‘)‘);            var CountM = obj.CountM;//總米數            count = CountM;            var CountPeople = obj.CountPeople;//總人數    //前台取得時候是用js.d來取

 

關於webservice返回json

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.