DeserializeObject for { "15 Days": "675", "180 Days": "8100", "30 Days": "1350", "60 Days": "2700", "90 Days": "4050" }
Asked
Active
Viewed 57 times
-1
-
I could not deserialize this one as the class object property cannot be started with numerical and space between them. It would be great of you if it could be solved. – binod maharjan Aug 26 '20 at 11:00
-
It would be great if we could arrange these values into an array separated by comma ',' like a[id1]="15 Days_675". – binod maharjan Aug 26 '20 at 11:10
-
I tried, but no luck. This will take time to research. But good question. – m.k.sharma Aug 26 '20 at 17:28
-
Can we use it in array? – binod maharjan Aug 31 '20 at 08:34
-
yes, we can convert to dictionary – m.k.sharma Aug 31 '20 at 10:21
-
you use dictionary instead of array. I have answer to convert into dictionary. – m.k.sharma Aug 31 '20 at 10:35
1 Answers
0
We can convert this json to dictionary. and this way around to handle this case. As we can directly deserialize to class object.
var test = "{ \"15 Days\": \"675\", \"180 Days\": \"8100\",
\"30 Days\": \"1350\", \"60 Days\": \"2700\", \"90 Days\":
\"4050\" }";
string [] json = test.Replace("{",
string.Empty).Replace("}", string.Empty).Split(',');
Dictionary<string, string> jsonDic = new Dictionary<string, string>();
for (int i = 0; i < json.Length; i++)
{
string[] jsonItem = json[i].Split(':');
jsonDic.Add(jsonItem[1], jsonItem[0]);
}
this dictionary jsonDic will look like below.
Hope this is helpful for you.

m.k.sharma
- 155
- 1
- 2
- 12
-
thank you, ManojKS Ji, it had worked for me, as I have implemented. – binod maharjan Sep 01 '20 at 11:50
-
Great, please don't mind to mark as answer for this question. This will motivate to work more on queries. – m.k.sharma Sep 01 '20 at 17:33