1
我有一個json自定義轉換器使用標準的asp.net庫。 我的轉換器看起來是這樣的:嵌套json自定義轉換器在C#與JavascriptConverter
public class MyObjectToJson : JavaScriptConverter
public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer)
{
MyObject TheObject = obj as MyObject;
Dictionary<string, object> OutputJson = new Dictionary<string, object>();
OutputJson.Add("SomeProperty", TheObject.Property1);
//line that I'm not figuring out
//I have a type MyNestedObject nested in the object model of MyObject
//I added that nested converter in the SupportedTypes method
OutputJson.Add("TheNestedObject",....?);
return OutputJson;
}
public override IEnumerable<Type> SupportedTypes
{
get { return new Type[] { typeof(MyObject), typeof(MyNestedObject) }; }
}
基本上,我有這就是所謂的MyNestedObjectJson另一個JSON自定義轉換器,但是我不知道在哪裏插上
小增加:每個轉換都會在'SupportedTypes'中返回它自己的類型。並非如初始文章所示 – Harry13 2016-09-05 13:20:34