I have the following JSON:
{
"graph": {
"edges": [{
"fromNode": "1",
"toNode": "2",
"distance": 200
}],
"nodes": [{
"id": "1",
"lat": 10.402875,
"lng": 53.611151
}]
}
}
For the deserialization I have this classes:
public class Graph {
public Node [] nodes { get; set; }
public Edge [] edges { get; set; }
}
public class Node {
public string id { get; set; }
public double lat { get; set; }
public double lng { get; set; }
}
public class Edge {
public string fromNode { get; set; }
public string toNode { get; set; }
public int distance { get; set; }
}
When I want to deserialize the JSON I call this function:
JsonConvert.DeserializeObject<Graph> (content);
Now I want to get the referenced node object in the edge class by the deserialization like this:
public class Edge {
public Node fromNode { get; set; }
public Node toNode { get; set; }
public int distance { get; set; }
}
Do you have an example for this without an foreach loop after the deserialization?