1 / 4

Web Services II: Returning Data in JSON Format

Web Services II: Returning Data in JSON Format. JSON vs XML. JSON is a data format that is easier for client-side programmers to work with It takes just one small change to an existing Web Service method to have it data in JSON format rather than their default XML format.

edythe
Download Presentation

Web Services II: Returning Data in JSON Format

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Web Services II: Returning Data in JSON Format

  2. JSON vs XML • JSON is a data format that is easier for client-side programmers to work with • It takes just one small change to an existing Web Service method to have it data in JSON format rather than their default XML format

  3. WS_MusicCategories: JSON version [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service to be called from script, using ASP.NET //AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService] public classWebService : System.Web.Services.WebService { publicWS_MusicCategories () { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod][ScriptMethod(ResponseFormat = ResponseFormat.Json)] public List<TO_MusicCategory>GetCategories() { DA_MusicCategoriescategoriesObject = new DA_MusicCategories(); returncategoriesObject.GetCategories()"; } }

  4. To have a Web Service Method return JSON data instead of XML: • Add the following line of code: [ScriptMethod(ResponseFormat = ResponseFormat.Json)] This line must be added immediately before the web method declaration (see example code on last slide.

More Related