2013-05-06 91 views
-3

;-) 我有一個問題來解析對象的JSON響應。C#JSON JavaScriptSerializer對象解析

我有以下對象:

public class Conferences : List<ConferenceData> 
{ 

} 

public class ConferenceData 
{ 
    private string _id; 
    private string _title; 
    private string _conference_code; 
    private string _conference_state; 
    private string _conference_type; 
    private string _datetime_start; 
    private int? _dial_type; 
    private string _moderator_code; 
    private int? _max_participants_count; 


    public string id 
    { 
     get { return _id; } 
     set { _id = value; } 
    } 
    public string title 
    { 
     get { return _title; } 
     set { _title = value; } 
    } 
    public string datetime_start 
    { 
     get { return _datetime_start; } 
     set { _datetime_start = value; } 
    } 
    public int? duration { get; set; } 
    public int? dial_type 
    { 
     get { return _dial_type; } 
     set { _dial_type = value; } 
    } 
    public string conference_type 
    { 
     get { return _conference_type; } 
     set { _conference_type = value; } 
    } 

    public string conference_state 
    { 
     get { return _conference_state; } 
     set { _conference_state = value; } 
    } 

    public bool? auto_recording { get; set; } 
    public string cost_centre { get; set; } 
    public int? participants_count { get; set; } 
    public int? security_code { get; set; } 
    public List<Participant> participants { get; set; } 
    public bool? broadcast_only_flag { get; set; } 
    public string moderator_code 
    { 
     get { return _moderator_code; } 
     set { _moderator_code = value; } 
    } 

與以下邏輯:

string json = "[{\"conference\":{\"conference_code\":\"208475\",\"conference_state\":\"planned\",\"conference_type\":\"scheduled\",\"datetime_start\":\"2013-04-30T15:30:00+02:00\",\"dial_type\":1,\"id\":\"7\",\"moderator_code\":\"652929\",\"scheduled_participants_count\":null,\"title\":\"betreff\"}},{\"conference\":{\"conference_code\":\"502012\",\"conference_state\":\"planned\",\"conference_type\":\"scheduled\",\"datetime_start\":\"2013-04-30T16:30:00+02:00\",\"dial_type\":1,\"id\":\"11\",\"moderator_code\":\"133140\",\"scheduled_participants_count\":null,\"title\":\"Betreff\"}},{\"conference\":{\"conference_code\":\"530437\",\"conference_state\":\"planned\",\"conference_type\":\"scheduled\",\"datetime_start\":\"2013-05-02T10:24:14+02:00\",\"dial_type\":1,\"id\":\"15\",\"moderator_code\":\"903257\",\"scheduled_participants_count\":null,\"title\":\"Test ui\"}}]"; 

    JavaScriptSerializer serializer = new JavaScriptSerializer(); 

    Conferences conferences = serializer.Deserialize<Conferences>(json); 

有什麼不對?我嘗試了很多不同的對象typs,.. ARRY,列表,字典,集合,...我無法找到合適的典型的... :-(

最好的問候! 馬克

+0

怎麼了?你告訴*美國*!什麼錯誤你好嗎? – 2013-05-06 09:39:50

+0

System.Collections.Generic.Dictionary'2 [System.Strin g,System.Object]不是類型WindowsFormsApplication2.ConferenceData的值,不能在此通用列表中使用。 Parametername:價值 – user2354047 2013-05-06 09:49:26

回答

1

只是聲明一個類

public class Conference 
{ 
    public ConferenceData conference; 
} 

和反序列化作爲

var conferences = serializer.Deserialize<List<Conference>>(json); 
+0

完美!有用!非常感謝! – user2354047 2013-05-06 09:52:57