I have to return a JSON string in a c# API which follows like:
{
"model" : 4 ,
"lang" : "en_US",
"parts" :
[
{
"id" : 1545,
"name" : "Part 1",
"part_types" :
{
"type 1" :
{
"url" : "part.com/type1",
"desc" : "has 6 bits"
},
"type 2" :
{
"url" : "part.com/type2",
"desc" : "has 7 bits."
}
}
}
]
}
I have a basic structure like:
public class inventory
{
public int model { get; set; }
public string lang { get; set; }
public part[] parts { get; set; }
}
public class part
{
public int id { get; set; }
public string name { get; set; }
public type types { get; set; }
}
public class type
{
public string url { get; set; }
public string desc { get; set; }
}
but I keep receiving the output like:
{
"model" : 4 ,
"lang" : "en_US",
"parts" :
[
{
"id" : 1545,
"name" : "Part 1",
"part_types" :
{
"url" : "part.com/type1",
"desc" : "has 6 bits"
}
}
]
}
I have 2 issues, one is when I run the API I can only display one type and if I try to make a List it adds [...] as in an array but I don't want an array I have to display a tittle for each type and then the details not in array form.
Second issue is under part_types I can not work out how to display the name of the part type before the details. If I try to add another class the name I set in the class is always displayed and I can not change it.
Any help would be very appreciated.