我有一个返回对象的 web 方法。我需要将此对象转换为 JSON 对象,以便我可以通过我的 android 应用程序使用它。因此,我的问题是我需要进行哪些更改才能将以下内容作为 JSON 对象返回?
aspx代码如下:
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; }
}
}
谢谢,任何帮助将不胜感激!