0

I have a JSON file and it contains a complex data that I need to convert into a DataSet.

{
"status_cd": "PE",
"fp": "072017",
"error_report": {
  "b2b": [
   {
    "inv": [
      {
        "val": 3623,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 138.1,
              "csamt": 0,
              "rt": 12,
              "txval": 2301.67,
              "camt": 138.1
            }
          },
          {
            "num": 2,
            "itm_det": {
              "samt": 34.65,
              "csamt": 0,
              "rt": 28,
              "txval": 247.51,
              "camt": 34.65
            }
          },
          {
            "num": 3,
            "itm_det": {
              "samt": 55.52,
              "csamt": 0,
              "rt": 18,
              "txval": 616.88,
              "camt": 55.52
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "11-07-2017",
        "rchrg": "N",
        "inum": "GCC006062"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01ACUPS3531N2ZS",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 227,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 12.14,
              "csamt": 0,
              "rt": 12,
              "txval": 202.32,
              "camt": 12.14
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "12-07-2017",
        "rchrg": "N",
        "inum": "GCC006099"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01DGRPS9260H1ZK",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 689,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 36.9,
              "csamt": 0,
              "rt": 12,
              "txval": 615.01,
              "camt": 36.9
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "14-07-2017",
        "rchrg": "N",
        "inum": "GCC006166"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01ARRPS5140D1ZX",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 250,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 13.39,
              "csamt": 0,
              "rt": 12,
              "txval": 223.22,
              "camt": 13.39
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "17-07-2017",
        "rchrg": "N",
        "inum": "GCC006285"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01ARRPS5140D1ZX",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 1478,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 79.2,
              "csamt": 0,
              "rt": 12,
              "txval": 1320,
              "camt": 79.2
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "17-07-2017",
        "rchrg": "N",
        "inum": "GCC006293"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01AFMPS1072H1ZC",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 1290,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 60.48,
              "csamt": 0,
              "rt": 12,
              "txval": 1008.01,
              "camt": 60.48
            }
          },
          {
            "num": 2,
            "itm_det": {
              "samt": 17.59,
              "csamt": 0,
              "rt": 28,
              "txval": 125.67,
              "camt": 17.59
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "17-07-2017",
        "rchrg": "N",
        "inum": "GCC006315"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01AJCTS9401L1Z8",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 6774,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 67.64,
              "csamt": 0,
              "rt": 12,
              "txval": 1127.3,
              "camt": 67.64
            }
          },
          {
            "num": 2,
            "itm_det": {
              "samt": 420.4,
              "csamt": 0,
              "rt": 18,
              "txval": 4671.06,
              "camt": 420.4
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "21-07-2017",
        "rchrg": "N",
        "inum": "GCC006580"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01CPOPS8196Q1Z0",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 410,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 13.59,
              "csamt": 0,
              "rt": 12,
              "txval": 226.54,
              "camt": 13.59
            }
          },
          {
            "num": 2,
            "itm_det": {
              "samt": 11.89,
              "csamt": 0,
              "rt": 18,
              "txval": 132.15,
              "camt": 11.89
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "22-07-2017",
        "rchrg": "N",
        "inum": "GCC006608"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01ASZPB4433B1Z3",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 749,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 57.13,
              "csamt": 0,
              "rt": 18,
              "txval": 634.83,
              "camt": 57.13
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "22-07-2017",
        "rchrg": "N",
        "inum": "GCC006612"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01ARRPS5140D1ZX",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 1318,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 100.54,
              "csamt": 0,
              "rt": 18,
              "txval": 1117.1,
              "camt": 100.54
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "22-07-2017",
        "rchrg": "N",
        "inum": "GCC006673"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01ANSPA6465C1Z3",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 197,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 10.54,
              "csamt": 0,
              "rt": 12,
              "txval": 175.61,
              "camt": 10.54
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "24-07-2017",
        "rchrg": "N",
        "inum": "GCC006726"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01ARRPS5140D1ZX",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 380,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 20.37,
              "csamt": 0,
              "rt": 12,
              "txval": 339.55,
              "camt": 20.37
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "25-07-2017",
        "rchrg": "N",
        "inum": "GCC006772"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01AACFI0598P126",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 2766,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 135.47,
              "csamt": 0,
              "rt": 12,
              "txval": 2257.8,
              "camt": 135.47
            }
          },
          {
            "num": 2,
            "itm_det": {
              "samt": 25.97,
              "csamt": 0,
              "rt": 28,
              "txval": 185.47,
              "camt": 25.97
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "25-07-2017",
        "rchrg": "N",
        "inum": "GCC006777"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01ACUPS3531N2ZS",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 738,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 17.56,
              "csamt": 0,
              "rt": 5,
              "txval": 702.39,
              "camt": 17.56
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "26-07-2017",
        "rchrg": "N",
        "inum": "GCC006823"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01AUXPS7983G2ZR",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 2439,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 62.88,
              "csamt": 0,
              "rt": 12,
              "txval": 1048,
              "camt": 62.88
            }
          },
          {
            "num": 2,
            "itm_det": {
              "samt": 96.52,
              "csamt": 0,
              "rt": 18,
              "txval": 1072.4,
              "camt": 96.52
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "26-07-2017",
        "rchrg": "N",
        "inum": "GCC006828"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01AABPG0741N1ZK",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 2439,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 62.88,
              "csamt": 0,
              "rt": 12,
              "txval": 1048,
              "camt": 62.88
            }
          },
          {
            "num": 2,
            "itm_det": {
              "samt": 96.52,
              "csamt": 0,
              "rt": 18,
              "txval": 1072.4,
              "camt": 96.52
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "26-07-2017",
        "rchrg": "N",
        "inum": "GCC006830"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01AABPG0741N1ZK",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 5979,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 313.09,
              "csamt": 0,
              "rt": 12,
              "txval": 5218.13,
              "camt": 313.09
            }
          },
          {
            "num": 2,
            "itm_det": {
              "samt": 10.27,
              "csamt": 0,
              "rt": 18,
              "txval": 114.09,
              "camt": 10.27
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "27-07-2017",
        "rchrg": "N",
        "inum": "GCC006871"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01ABWPG7905P1ZY",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 4879,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 212.83,
              "csamt": 0,
              "rt": 12,
              "txval": 3547.23,
              "camt": 212.83
            }
          },
          {
            "num": 2,
            "itm_det": {
              "samt": 69.15,
              "csamt": 0,
              "rt": 18,
              "txval": 768.3,
              "camt": 69.15
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "28-07-2017",
        "rchrg": "N",
        "inum": "GCC006943"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01ACUPS3531N2ZS",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 2756,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 147.66,
              "csamt": 0,
              "rt": 12,
              "txval": 2460.97,
              "camt": 147.66
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "29-07-2017",
        "rchrg": "N",
        "inum": "GCC007016"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01AJCTS9401L1Z8",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 2857,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 38.59,
              "csamt": 0,
              "rt": 12,
              "txval": 643.16,
              "camt": 38.59
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "31-07-2017",
        "rchrg": "N",
        "inum": "GCC007047"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01AUXPS7983G2ZR",
    "error_cd": "RET191113"
  },
  {
    "inv": [
      {
        "val": 1296,
        "itms": [
          {
            "num": 1,
            "itm_det": {
              "samt": 69.45,
              "csamt": 0,
              "rt": 12,
              "txval": 1157.57,
              "camt": 69.45
            }
          }
        ],
        "inv_typ": "R",
        "pos": "01",
        "idt": "31-07-2017",
        "rchrg": "N",
        "inum": "GCC007110"
      }
    ],
    "error_msg": "The GSTIN is invalid. Please enter a valid GSTIN.",
    "ctin": "01AASPJ1987C1ZX",
    "error_cd": "RET191113"
  },      
]
},
"gstin": "01AAYPG1879R1ZV"
}

I have tried deserializing it into generic data-table but it wont work as well. using class structure it is not fitting properly. can anyone tell me how to resolve it.

Error is:

Newtonsoft.Json.JsonSerializationException: 'Additional text found in JSON string after finishing deserializing object'

4
  • I have tried various methods but not able to get it correctly. - then, please share what you have tried that doesn't work. From How to Ask: Help others reproduce the problem: Not all questions benefit from including code. But if your problem is with code you've written, you should include some. If you can edit your question and include a minimal reproducible example demonstrating how to get the exception, it's more likely we will be able to help. Commented Oct 24, 2017 at 7:20
  • Duplicate: stackoverflow.com/questions/19136024/… Commented Oct 24, 2017 at 7:22
  • @khmub no it is not Commented Oct 24, 2017 at 7:27
  • Rather than posting just your JSON, post also the code that handles your JSON! And show us where you get the error. Commented Oct 24, 2017 at 7:30

1 Answer 1

1

Your JSON is not of a fitting format to convert straight to a DataSet. Instead you can deserialize into a class and then take steps from there.

The class:

public class ItmDet
{
    public double samt { get; set; }
    public int csamt { get; set; }
    public int rt { get; set; }
    public double txval { get; set; }
    public double camt { get; set; }
}

public class Itm
{
    public int num { get; set; }
    public ItmDet itm_det { get; set; }
}

public class Inv
{
    public int val { get; set; }
    public List<Itm> itms { get; set; }
    public string inv_typ { get; set; }
    public string pos { get; set; }
    public string idt { get; set; }
    public string rchrg { get; set; }
    public string inum { get; set; }
}

public class B2b
{
    public List<Inv> inv { get; set; }
    public string error_msg { get; set; }
    public string ctin { get; set; }
    public string error_cd { get; set; }
}

public class ErrorReport
{
    public List<B2b> b2b { get; set; }
}

public class RootObject
{
    public string status_cd { get; set; }
    public string fp { get; set; }
    public ErrorReport error_report { get; set; }
    public string gstin { get; set; }
}

Then you just deserialize it as so:

var data = JsonConvert.DeserializeObject<RootObject>(json);

FYI this is what JSON that can be deserialized straight to a DataSet looks like:

{
    "Table1": [
    {
        "Value1": "ABC",
        "Value2": "123"
    }
    ],
    "Table2": [
    {
        "Value1": "DEF",
        "Value2": "456"
    }
    ]
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.