Asp.net_webservice return JSON

Source: Internet
Author: User

[WebMethod] PublicList<picturemanager>Loadpictureone () {Datadatacontext context=NewDatadatacontext (); List<PictureManager> list =NewList<picturemanager>(); Try{List<PictureManager> li = context. Picturemanager.where (p = P.typeid = =2&& P.isshow = =true). OrderByDescending (p = p.id). Take (8).                ToList (); foreach(Picturemanager Iteminchli) {picturemanager TB=NewPicturemanager (); 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 NewException (ex.            Message); }            returnlist; }
//Load Picture 1function Loadpictureone () {$ ("#div1"). HTML (""); varHtmlinfo =""; $.ajax ({type:"Post", ContentType:"Application/json;charset=utf-8", URL:".. /.. /service/backstageservice.asmx/loadpictureone", Data:"", DataType:"JSON", success:function (result) {vardata =eval (RESULT.D); $ (data). each (function () {Htmlinfo+="<div class= ' moxin ' ><div >"+ 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 +"\ ") ' ></li></ul></div>";            }); $("#div1"). HTML ($.trim (htmlinfo)); }, Error:function (err) {Layer.alert ("Error loading picture",5); }    });}

If a single object is returned:
The value of RESULT.D is:"{" BRXM ":" AA "," ys ":" BB "," KS ":" CC "," HM ":" 123 "," SJ ":" 08:50 "}"
Eval ("(" +result.d+ ")") try it.

[WebMethod] Public stringGetCount () {stringJSON =string.            Empty; Try            {                using(Datadatacontext context =NewDatadatacontext ()) {                    if(Context.tb_ApplicationAward.Count ()! =0)                    {                        intCountm = Convert.ToInt32 (context.tb_applicationaward.sum<tb_applicationaward> (p =p.schedulelength)); if(Countm > -) {Countm= -; }                        intCountpeople =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) {varobj = eval ('('+ JS.D +')'); varCountm = obj. Countm;//total number of metersCount =Countm; varCountpeople = obj. Countpeople;//Total number//The front desk is made with JS.D.

Asp.net_webservice return JSON

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.