0
にJSON文字列に変換します。は私が<code>{field:'DateToEnd',dir:'asc'}</code></p> <p>のようなJSON文字列を持っていると私は2つのプロパティを次のように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(newtonsoft.json) – deeiip
をエラーは何ですか? –
'serialize.Deserialize(fixSortString);' –