0

My json string is as below:

  "KEY1": {
    "VALUE1": 44.0,
    "VALUE2": "1HO10490",
    "VALUE3": "2019-05-30",
    "VALUE4": null,
    "VALUE5": 3.7,
    "VALUE6": 222
  },
  "KEY2": {
    "VALUE1": 48.0,
    "VALUE2": "1HO11031",
    "VALUE5": "2019-05-30",
    "VALUE8": null,
    "VALUE9": 3.4,
    "VALUE4": 222,
    "VALUE10": 310
  },
  "KEY3": {
    "VALUE1": null,
    "VALUE2": null
  }
}

My class object is :

public class Thing    {   

        public long VALUE1 { get; set; }         
        public long VALUE2 { get; set; }        
        public string VALUE3 { get; set; }        
        public string VALUE4 { get; set; }        
        public string VALUE5 { get; set; }
       public string VALUE6 { get; set; }
       public string VALUE7 { get; set; }
      public string VALUE8 { get; set; }
      public string VALUE9 { get; set; }
      public string VALUE10 { get; set; }
    }

 public class Big
    {      

        Dictionary<string,Thing> Things { get; set; }
    }

var values = JsonConvert.DeserializeObject<Big[]>(jsonString);

It gives me the following error: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'Models.Big[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.

Appreciate quick help!

Thanks Nalini

Nalini
  • 11
  • 1
  • @ŇɏssaPøngjǣrdenlarp, i tried doing that like below: public class First { public string key { get; set; } public Thing Value { get; set; }} public class Second { public List first {get;set;} – Nalini Feb 12 '20 at 00:26
  • @ŇɏssaPøngjǣrdenlarp, var temp=jsonConvert.DeserializeObject>(jsonString). It threw the exception again – Nalini Feb 12 '20 at 00:33
  • Your `JSON` string posted in the question is incorrect. If you want a resolution, please provide the correct string. – Rahul Sharma Feb 12 '20 at 06:50

0 Answers0