我想将以下 JSON 淡化为强类型 C# 对象:
{"myThings":{"One thing":"aaaaa","Two thing":"bbbbb"}}
一件事和两件事并不总是被称为一件事和两件事,它们每时每刻都在变化时间,可能会有或多或少的 myThings。
我不知道 myThings 应该是什么类型的对象,我在想一个 KeyValuePair 但不确定 Json.Net 是否支持反序列化为键/值对,或者这是否是偶数正确的。有人可以确认吗?
谢谢
请您参考如下方法:
class MyThings
{
public string OneThing { get; set; }
public string TwoThing { get; set; }
}
或
class MyThings
{
public Dictionary<string, string> Dictionary { get; set; }
}
如果“X 事物”的数量未知且可变,请使用 Dictionary<string, string> .如果你总是要{"One thing":"aaaaa","Two thing":"bbbbb"}使用第一类。
编辑: 根据您的编辑,使用 Dictionary<string, string>
