How do I make my aspx web method return the list as a JSON object?

labtr0

New Member
I have a web method that returns a object. I need to convert this object to a JSON object so that i can consume it through my android application.Therefore my question is what changes do i need to make in order to return the following as JSON Object?The aspx code is as follows:\[code\]using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Services;using System.Web.Script.Services;namespace WebService4{ /// <summary> /// Summary description for Service1 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService] public class Service1 : System.Web.Services.WebService { [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public List<Vehicle> GetCustomerList() { Vehicle vehi = simpleCase(); List<Vehicle> newL = new List<Vehicle> { vehi }; return newL; } [WebMethod] public Vehicle simpleCase() { Vehicle obj = new Vehicle(); obj.VehicleID = "KL-9876"; obj.VehicleType = "Nissan"; obj.VehicleOwner = "Sanjiva"; return obj; } } //someObject.SomeMethod(obj); public class Vehicle { public string VehicleID { get; set; } public string VehicleType { get; set; } public string VehicleOwner { get; set; } }}\[/code\]Thanks and any help would be highly appreciated!
 
Back
Top