MrB3NiT0
MrB3NiT0

Reputation: 147

Json deserializeObject

Hi I want to deserialize this Json :

{
  "engine_name": "Hermle",
  "criterion": {
    "squareness": {
      "name": "perpendicularité",
      "theoretical": "5",
      "expected": "5"
    },
    "backlash": {
      "name": "jeu à l'inversion",
      "theoretical": "5",
      "expected": "5"
    },
    "straightness": {
      "name": "rectitude",
      "theoretical": "1",
      "expected": "1"
    },
    "spindle-runout": {
      "name": "faux rond broche",
      "theoretical": "5",
      "expected": "5"
    },
    "circularity": {
      "name": "circularité",
      "theoretical": "5",
      "expected": "5"
    }
  }
}

I have my class object :

public class SmartDevice
{
    public string Engine_name { get; set; }
    public Object criterion { get; set; }
}

This works great but I can't have Count propertie for criterion Object so I want to have a list of criterion but I don't know how to do this.

Upvotes: 1

Views: 120

Answers (2)

Meikel
Meikel

Reputation: 324

You could go with a Dictionary<string, object> or instead of object go with a custom type like CriteriaObject.

Upvotes: 2

&#211;scar Andreu
&#211;scar Andreu

Reputation: 1700

As you define the problem, it's imposible to get count from criterion because it is an object and not a list or an array. To be able to have a criterion list you need something like this:

{
  "engine_name": "Hermle",
  "criterion": [
    {
     "type": "squareness",
      "name": "perpendicularité",
      "theoretical": "5",
      "expected": "5"
    },
    {    
     "type": "circularity",
      "name": "circularité",
      "theoretical": "5",
      "expected": "5"
    }
  ] 
}

And the class should look like this:

public class SmartDevice
{
    public string Engine_name { get; set; }
    public List<Object> criterion { get; set; }
}

Upvotes: 0

Related Questions