0
我有一個JSON字符串等{field:'DateToEnd',dir:'asc'}
轉換JSON字符串到C#類對象
,我已經在c#與以下兩個屬性的類。
public class SortDescriptor
{
public SortDescriptor()
{
}
public string Field { get; set; }
public string Dir { get; set; }
}
現在我想將此字符串轉換爲類對象,以便我可以訪問屬性。
我試過下面的例子。但它不適合我。
JavaScriptSerializer serialize = new JavaScriptSerializer();
SortDescriptor sort = (SortDescriptor)serialize.DeserializeObject(fixSortString);
它提供了以下錯誤:
Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]' to type 'NF.Common.SortDescriptor'.
任何人都可以讓我知道,我怎麼能做到這一點?
使用json.net – deeiip
什麼是錯誤? –
'serialize.Deserialize(fixSortString);' –