我有JSON這樣的:
編輯:JSON是錯誤的。發送json對象數組到.net web服務
[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public string ProcessData(VehiclesData VehiclesData)
{
//...Do stuff here with VehiclesData
}
public class VehiclesData
{
public List<Vehicle> VehiclesList = new List<Vehicle>();
public class Vehicle
{
private string year = string.Empty;
private string make = string.Empty;
private string model = string.Empty;
public string Year { get { return this.year; } set { this.make = value; } }
public string Make { get { return this.make; } set { this.make = value; } }
public string Model { get { return this.model; } set { this.model = value; } }
}
}
我收到「對象不匹配目標類型」:我曾用手
var VehiclesData = {
"VehiclesData": {
"VehiclesList": [
{ "year": "2010", "make": "honda", "model": "civic" },
{ "year": "2011", "make": "toyota", "model": "corolla" },
{ "year": "2012", "make": "audi", "model": "a4" }]
}
}
我想發送給.NET Web服務API這樣的類型吧。
有了扁平的JSON對象,我得到的數據很好,但對象和一個C#列表的數組,我有點失落。
你的json無效http://json2csharp.com/ – saj 2014-10-01 01:43:05