I would like to get next structure in JSON:
{
'for-sale': { name: 'For Sale', type: 'folder' },
'vehicles': { name: 'Vehicles', type: 'folder' },
'rentals': { name: 'Rentals', type: 'folder' },
}
I can use JavaScriptSerializer to convert .net class to JSON format. But witch structure my class must have for above sample data?
解决方案
Have you tried this:
public class MyClass
{
[JsonProperty("for-sale")]
public IList forSale { get; set; }
public IList vehicles { get; set; }
public IList rentals { get; set; }
}
public class Item
{
public string name { get; set; }
public string type { get; set; }
}
You could also use the DataContractJsonSerializer and instead you would use the following classes:
[DataContract]
public class MyClass
{
[DataMember(Name = "for-sale")]
public IList forSale { get; set; }
[DataMember]
public IList vehicles { get; set; }
[DataMember]
public IList rentals { get; set; }
}
[DataContract]
public class Item
{
[DataMember]
public string name { get; set; }
[DataMember]
public string type { get; set; }
}