次のような JSON があります。
{
"MobileSiteContents": {
"au/en": [
"http://www.url1.com",
"http://www.url2.com",
],
"cn/zh": [
"http://www.url2643.com",
]
}
}
私はそれを次のIEnumerable
ようなクラスに逆シリアル化しようとしています:
public class MobileSiteContentsContentSectionItem : ContentSectionItem
{
public string[] Urls { get; set; }
}
public abstract class ContentSectionItem
{
public string Culture { get; set; }
}
それは可能ですか?
これにはおそらくカスタム JsonConverter を使用する必要があると思いますが、例が見つかりません。
を使用して変換する方法を書き始めましたJObject.Parse
が、これが正しい/最も効率的な方法であるかどうかはわかりません:
public IEnumerable<MobileSiteContentsContentSectionItem> Parse(string json)
{
var jobject = JObject.Parse(json);
var result = new List<MobileSiteContentsContentSectionItem>();
foreach (var item in jobject.Children())
{
var culture = item.Path;
string[] urls = new[] { "" }; //= this is the part I'm having troble with here...
result.Add(new MobileSiteContentsContentSectionItem { Culture = culture, Urls = urls });
}
return result;
}