{
"id" : 0,
"name" : "meeting",
"text" : "10 pm",
"location" : "Place1",
"startdate" : "10/27/2012 17:11",
"enddate" : "10/27/2012 18:41",
"description" : "Description",
"chairman" : "0",
"members" : [2, 1],
"messagetype" : {
"SMS" : false,
"Email" : true
},
"smsmessage" : null,
"emailmessage" : "this is message",
"emailsubject" : null,
"reminder" : "5",
"timetosendemail" : "10/23/2012 00:00",
"timetosendsms" : null
}
これは私のjson文字列です。必要なのは、この文字列を解析し、各値をクラスの特定のメンバーに格納することです。
クラスはこんな感じ
public class Event
{
public int id { get; set; }
public string name {get;set;}
public string text { get; set; }
public DateTime start_date { get; set; }
public DateTime end_date { get; set; }
public string location { get; set; }
public double ReminderAlert { get; set; }
public MessagerType MessageType { get; set; }
public string SmsMessage { get; set; }
public string EmailMessage { get; set; }
public string EmailSubject { get; set; }
public DateTime TimeToSendEmail { get; set; }
public DateTime TimeToSendSMS { get; set; }
public string[] members {get;set;}
}
Json.net ライブラリを使用して解析しました..コードスニペットを以下に示します
var eventValues = JsonConvert.DeserializeObject<List<Dictionary<string, Event>>>(stringEvent);
このコードを実行した後、このエラーが発生します
現在の JSON オブジェクト ({"name":"value"} など) を型 'System.Collections.Generic.List
1[System.Collections.Generic.Dictionary
2[System.String,CalendarScheduler.Models.Event]]' に逆シリアル化できません。型には JSON 配列 (例 [1,2,3]) 正しく逆シリアル化します。このエラーを修正するには、JSON を JSON 配列 ([1,2,3] など) に変更するか、逆シリアル化された型を通常の .NET 型 (整数のようなプリミティブ型ではなく、コレクション型ではない) に変更します。 JSON オブジェクトから逆シリアル化できる配列またはリスト)。JsonObjectAttribute を型に追加して、強制的に JSON オブジェクトから逆シリアル化することもできます。
パス「id」、行 1、位置 6。
この例外を回避するにはどうすればよいですか?