Android Development Diary (iv)

Source: Internet
Author: User

Create a new table ad on the server-side database

In the DATAINFO.EDXM model, click Update model from database, publish.

A new entity ad is created.

Then create a new CS file

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingsystem.web;5 usingSYSTEM.WEB.MVC;6 usingNewtonsoft.json;7 usingNewtonsoft.Json.Linq;8 9 namespacewebjson.controllersTen { One      Public classAdshowcontroller:controller A     { -Datainfo Storedb =Newdatainfo (); -          PublicJarray Index (intAdid) the         { -Ienumerable<ad>AD; -AD = storedb.ad.Where (U = u.adid = =adid); -             stringAdjson =Jsonconvert.serializeobject (AD); +Jarray Adjarray =Jarray.parse (Adjson); -  +             returnAdjarray; A  at         } -     } -}
View Code

You can then publish the JSON array object that you passed on the web side.

Http://59.78.93.208:9092/AdShow?adid=1

Writing service files on the Android side

1  Public classAdshowservice {2      PublicJsonarray getadshowdetails (String adid)3     {4String url= "http://59.78.93.208:9092/AdShow?adid=" +adid+ "";5HttpClient client =Newdefaulthttpclient ();6Client.getparams (). Setparameter (Coreconnectionpnames.connection_timeout, 3000);7Client.getparams (). Setparameter (Coreconnectionpnames.so_timeout, 3000 );8 HttpPost request;9         Try {TenRequest =NewHttpPost (NewURI (URL)); OneHttpResponse response =Client.execute (request); A             if(Response.getstatusline (). Getstatuscode () = = 200) { -httpentity entity =response.getentity (); -                 if(Entity! =NULL) { theString out =entityutils.tostring (entity); -Jsonarray jsonarray=NewJsonarray (out); -                     returnJsonarray; -                 } +             } -}Catch(Exception e) { + e.printstacktrace (); A             return NULL; at         } -         return NULL; -     } -  -}
View Code

Android Development Diary (iv)

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.