0

I have a JSON object that I'm struggling to convert to a C# class. Can anyone point me to the right direction ? How do you convert the marker section into a C# Class since the markers have a string followed by array. I've included the JSON return and also my class below. Any help or pointers ?

Thanks !

JSON:

{
 "markers": {
  "/New Quota (1)/two": {
   "limit": 50,
   "pending": 0,
   "oq": 0,
   "complete": 0
  },
  "/New Quota/AoAos/bo8Oi": {
   "limit": 20,
   "pending": 0,
   "oq": 0,
   "complete": 0
  },
  "/New Quota (1)/one": {
   "limit": 50,
   "pending": 0,
   "oq": 0,
   "complete": 0
  }
 },
 "priority": {
  "/New Quota (1)/one": 2
 },
 "plus": [
  "four",
  "five",
  "three",
  "two",
  "one"
 ],
 "sheets": {
  "New Quota (1)": [
   {
    "cellCount": 1,
    "tableTotal": 250,
    "tableIndex": 0
    "cells": [
     {
      "marker": "/New Quota (1)/one",
      "components": [
       "one"
      ]
     },
     {
      "marker": "/New Quota (1)/two",
      "components": [
       "two"
      ]
     }
    ]}]
 },
 "stopped": {
  "/New Quota/AoAos/s9oVa": "erwin on 02/24/2015 12:48"
 },
 "defines": {
  "XiiZn": {
   "cond": "(q1.r6)",
   "description": "55-64"
  },
  "LvmQy": {
   "cond": "(q1.r2)",
   "description": "18-24"
  }
 }
}    




public class RootObject
{

    public Sheet sheets { get; set; }
    public Marker marker { get; set; }

}

public class Marker
{

    public Dictionary<string,MarkerAttribute> markerAttribute { get; set; }
}

public class MarkerAttribute
{
    public int limit { get; set; }
    public int oq { get; set; }
    public int pending { get; set; }
    public int complete { get; set; }
}

public class Sheet
{
    public SheetAttribute sheetAttribute { get; set; }

}

public class SheetAttribute
{
    public int cellCount { get; set; }
    public int tableTotal { get; set; }
    public int tableIndex { get; set; }
    public string description { get; set; }
    public List<SheetCells> cells { get; set; }
}

public class SheetCells
{
    public string marker { get; set; }
    public List<string> component { get; set; }
}
johnD
  • 29
  • 2
  • That's an object, not an array. What's the problem? – SLaks Dec 20 '18 at 20:28
  • You can deserialize `markers` and `priority` into properties of type `Dictionary` for some appropriate `T` as shown in [How can I parse a JSON string that would cause illegal C# identifiers?](https://stackoverflow.com/a/24536564/3744182) or [Deserializing JSON when key values are unknown](https://stackoverflow.com/a/24901245/3744182) – dbc Dec 20 '18 at 20:31
  • @dbc I've made the Marker as a dictionary and yet the deserialize won't work correctly . `public Dictionary marker { get; set; }` – johnD Dec 20 '18 at 21:44
  • 1
    I'm an idiot. It's markers..... Thank @dbc – johnD Dec 20 '18 at 21:48

0 Answers0