I have the below model and I want to access the Name and Type from the class Property:
public partial class RootObject
{
[JsonProperty("edmx:Edmx")]
public EdmxEdmx EdmxEdmx { get; set; }
}
public partial class EdmxEdmx
{
[JsonProperty("EntityType")]
public List<EntityType> EntityType { get; set; }
}
public partial class EntityType
{
[JsonProperty("-Name")]
public string Name { get; set; }
[JsonProperty("Property")]
public List<Property> Property { get; set; }
}
public partial class Property
{
[JsonProperty("-Name")]
public string Name { get; set; }
[JsonProperty("-Type")]
public String Type { get; set; }
}
I have done the below:
var r = JsonConvert.DeserializeObject<RootObject>(o1.ToString());
How do I write a loop that accesses name and type ?
Edit: Here is my JSON:
{
"edmx:Edmx": {
"-xmlns:edmx": "http://docs.oasis-open.org/odata/ns/edmx",
"-Version": "4.0",
"EntityType": [
{
"-BaseType": "mscrm.crmbaseentity",
"-Name": "EntityA",
"Property": [
{
"-Name": "address2_line1",
"-Unicode": "false",
"-Type": "Edm.String"
},
{
"-Name": "territorycode",
"-Type": "Edm.Int32"
},
{
"-Name": "EntityID",
"-Type": "Edm.Guid"
},
{
"-Name": "address1_telephone1",
"-Unicode": "false",
"-Type": "Edm.String"
}
]
}
}
}
The above JSON is the o1.ToString. I use a JObject to create a JSON object from a text file.
EDIT2:
Let me try to be more precise:
I want to get this per entity:

Typeproperty is withinProperty, and there are multiple properties. What value would you expect to get from the JSON you've shown?