我需要将带有点的属性名称的json映射到等效的嵌套c#类。
例如我有如下JSON字符串:
{
"DateProcessed": "20170215T005736+0530", //e.g.to ProcessedDate in C# class
"WordCount" :346,
"Content.Headline": "This is just the headline",
"Content.Href": "http://www.samplesssss.test",
"Content.Text": "This is the big text represntation here that defines the summary structure.",
"Content.Thumbnail.Href" : "http://imagetest.test.intr",
"Content.Thumbnail.Height" : "245",
"Content.Thumbnail.Width" :"345",
"Content.Thumbnail.UnitType" :"centimeter"
}
我需要将上面的JSON字符串映射到下面提到的C#类:
public class Body
{
public Datetime ProcessedDate {get;set;}
public int WordCount {get;set;}
public Format Content {get;set;}
}
public class Content
{
public string Headline {get;set;}
public string Href {get;set;}
public string Text {get;set;}
public ImageHolder Thumbnail {get;set;}
}
public class ImageHolder
{
public string Href {get;set;}
public int Height {get;set;}
public int Width {get;set;}
public string UnitType {get;set;}
}
如何将上述JSON映射到C#类真的很无能为力。我尝试使用传统方法分割字符串并尝试在C#类中找到等效的匹配属性名称,但它变得如此混乱我不得不停止并删除所有内容。任何方法都会非常有用。希望SO专业知识能够挽救我的一天。