У меня JSON:
EDITED: JSON ошибался. Я напечатал его вручнуюОтправка массива объектов json на .net веб-сервис
var VehiclesData = {
"VehiclesData": {
"VehiclesList": [
{ "year": "2010", "make": "honda", "model": "civic" },
{ "year": "2011", "make": "toyota", "model": "corolla" },
{ "year": "2012", "make": "audi", "model": "a4" }]
}
}
Я пытаюсь отправить это к API .net веб-службы, как это:
[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; } }
}
}
Я получаю «объект не соответствует целевой тип».
С плоскими объектами JSON я получаю данные просто отлично, но с массивом объектов и списком C#, я немного потерян.
Ваш json недействителен http://json2csharp.com/ – saj