【发布时间】:2014-11-25 18:56:40
【问题描述】:
我有这样的 JSON:
编辑:JSON 是错误的。我是手写的
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:
[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 无效json2csharp.com
标签: c# asp.net json web-services asmx