The JSON string that I receive is inconsistent. Sometimes some of the data elements in the JSON return as 'List ' type, the other times return as 'dictionary' type. Currently using JavaScriptSerializer to Deserialize the JSON string, but it gives me an exception in the cases like
for example - I have a data field "jpjhseq" which I have declared as a dictionary but at times the JSON string returns this as a string and I get an exception. This issue happens for other fields as well.
JavaScriptSerializer serializer = new JavaScriptSerializer();
Foo foo = serializer.Deserialize<Foo>(jsonString);
Many a times I get following json string
{"element1":{"0":"0","1":"S","2":"S","3":"J","4":"Q","5":"X","6":"M"},"element2":{"1":"one" ,"2":"two","4":"four","5":"five","6":"six","7":"seven","8":"eight"}}
for other data i get following json string
{"element1":["0","S","S","J","Q","X","M"],"element2":["one" ,"two","four","five","six","seven","eight"]}
How can i write a generic json parser for such inconsistent json strings? Key names will be standard, but the data type of their values may vary.
What can be done to resolve this issue?