[{ “程序”:“易趣 美国”, “日期”: “/日期(1384108200000)/”, “TimePlus”: “/日期(-62135596800000)/”, “运动”: “cwsi12”, “点击次数”:0, “EPC”:3.3799, “收入”:6.7599 “的CampaignID”: “5337412363”, “印象”: “0”, “状态”:“重复 在数据库“},{”程序“:”eBay 美国”, “日期”: “/日期(1384108200000)/”, “TimePlus”: “/日期(-62135596800000)/”, “运动”: “cwsi12”, “点击次数”:0, “EPC”:3.3799, “收入”:6.7599 “的CampaignID”: “5337412363”, “印象”: “0”, “状态”:“重复 在数据库“},{”程序“:”eBay 美国”, “日期”: “/日期(1384108200000)/”, “TimePlus”: “/日期(-62135596800000)/”, “运动”: “cwsi12”, “点击次数”:0, “EPC”:3.3799, “收入”:6.7599 “的CampaignID”: “5337412363”, “印象”: “0”, “状态”:“重复 在数据库“},{”程序“:”eBay 美国”, “日期”: “/日期(1384108200000)/”, “TimePlus”: “/日期(-62135596800000)/”, “运动”: “cwsi12”, “点击次数”:0, “EPC”:3.3799, “收入”:6.7599 “的CampaignID”: “5337412363”, “印象”: “0”, “状态”:“重复 在数据库“}]
public class EbayEarnings_Temp
{
public String Program { get; set; }
public DateTime Date { get; set; }
public DateTime TimePlus { get; set; }
public String Campaign { get; set; }
public int Clicks { get; set; }
public decimal EPC { get; set; }
public decimal Earnings { get; set; }
public String CampaignID { get; set; }
public String Impression { get; set; }
public string Status { get; set; }
}
var serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(EbayEarnings_Temp));
var c = (EbayEarnings_Temp)serializer.ReadObject(jsonString);
我收到此错误
答案 0 :(得分:1)
消息是json对象而不是列表。您必须手动集成序列化程序或序列化json对象。 我认为它看起来应该是这样的:
public ActionResult action(Object Message)
{
// deserialise if Object Message is a string
var serializer = new JavaScriptSerializer();
var c = serializer.Deserialize<YourClass>(Message);
// deserialise if Object Message is a JsonObject
var serializer = new DataContractJsonSerializer(typeof(YourClass));
var c = (YourClass)serializer.ReadObject(Message);
return PartialView(Message);
}
或其他解决方案:
我使用库Newtonsoft.Json。如果你打算在你的情况下使用它,它看起来像:
...
MyClass m = JsonConvert.DeserializeObject<Message>(message.ToString());
var status = m.Status; //...and so on