class Program
{
static void Main(string[] args)
{
string json = JsonConvert.SerializeObject(new Account { Name = "test" }, Newtonsoft.Json.Formatting.Indented,
new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All, PreserveReferencesHandling = PreserveReferencesHandling.Objects });
Console.Out.Write(json);
while (true)
{
}
}
}
class Account {
public String Name;
}
嘿,我试图进入Json。我想反序列化一个对象。我想从字符串中获取类型信息。因此,当我反序列化时,我希望json能够自己识别类型而不指定它。这可能吗?
最诚挚的问候, 布赖恩
答案 0 :(得分:1)
var myObject = JObject.Parse(jsonString)
var someObject = myObject["myOtherObject"]["otherThing"];
var myString = (string) someObject["theString"];
我发现Json.net的这一部分非常有用,我希望它可以帮助你:)