-1

I am converting Json to Object using DeserializeObject.but after convert into an object I am getting Jproperty in MongoDB instead of the correct value.


JSON

{
   {
  "BILL_INFO": {
    "BILL_RUN": {
      "BILL_CYCLE_INFO": {
        "BILL_CYCLE_ID": "20200218",
        "BILL_CYCLE_BEGIN": "18/02/2020",
        "BILL_CYCLE_END": "18/03/2020",
        "DUE_DATE": "10/04/2020"
      },

}
 BillDetails_Temp2 tempObj2 = JsonConvert.DeserializeObject<BillDetails_Temp2>(json);

 public class BillDetails_Temp2
    {
        public object BILL_INFO { get; set; }
    }


Output :

"BILL_INFO": {
                "_t": "JObject",
                "_v": [{
                    "_t": "JProperty",
                    "_v": [{
                        "_t": "JObject",
                        "_v": [{
                            "_t": "JProperty",
                            "_v": [{



nani
  • 15
  • 2
  • 6

1 Answers1

0

You have to strongly type your object, try this code:

    public partial class BillDetails_Temp2
    {
        [JsonProperty("BILL_INFO")]
        public BillInfo BillInfo { get; set; }
    }

    public partial class BillInfo
    {
        [JsonProperty("BILL_RUN")]
        public BillRun BillRun { get; set; }
    }

    public partial class BillRun
    {
        [JsonProperty("BILL_CYCLE_INFO")]
        public BillCycleInfo BillCycleInfo { get; set; }
    }

    public partial class BillCycleInfo
    {
        [JsonProperty("BILL_CYCLE_ID")]
        [JsonConverter(typeof(ParseStringConverter))]
        public long BillCycleId { get; set; }

        [JsonProperty("BILL_CYCLE_BEGIN")]
        public string BillCycleBegin { get; set; }

        [JsonProperty("BILL_CYCLE_END")]
        public string BillCycleEnd { get; set; }

        [JsonProperty("DUE_DATE")]
        public string DueDate { get; set; }
    }
...

 BillDetails_Temp2 tempObj2 = JsonConvert.DeserializeObject<BillDetails_Temp2>(json);

Jakub Kozera
  • 3,141
  • 1
  • 13
  • 23
  • @kabek I understand Lets' say we have hundreds of lines it's difficult right to create props for all. – nani May 15 '20 at 14:12
  • and what do you need to do with all of those props? – Jakub Kozera May 15 '20 at 14:27
  • Just save in MongoDB as the Object column type. I don't need properties. I am nothing to do with that. Save JSON format data in Object for Mongodb. – nani May 15 '20 at 14:32