我有以下JSON字符串:C#對象表示
{
"region" : {
"center" : {
"title" : "Center Region"
},
"east" : {
"title" : "East Region - Form"
}
},
"buttons" : {
"save" : "Save"
},
"fields" : {
"labels" : {
"firstName" : "First Name",
"lastName" : "Last Name",
"chooseLocale" : "Choose Your Locale"
}
}
}
我想知道是否這(見下文)是JSON字符串的C#中的正確的表示:
public class Region
{
public Region() {}
}
public class Center : Region
{
public Center(){}
public string title{get; set;}
}
public class East : Region
{
pubic East(){}
public string title{get; set;}
}
public class Buttons
{
public Buttons(){}
public string save{get; set;}
}
public class Fields
{
public Fields(){}
}
public class Labels : Fields
{
public Labels(){}
public string firstName{get; set;}
public string lastName{get; set;}
public string chooseLocale{get; set;}
}
我需要正確的對象表示,然後我可以使用JsonConvert.SerializeObject(object);
進行序列化,以生成上面的JSON字符串。
http://json2csharp.com/工作的對待 – RoughPlace
在ASP.NET和Web Tools 2012.2+中,您還有['將JSON粘貼爲類'] (http://blogs.msdn.com/b/webdev/archive/2012/12/18/paste-json-as-classes-in-asp-net-and-web-tools-2012-2-rc.aspx ) – khellang