I got the following exception in the foreach statement of my code snippet below:
exception:System.InvalidCastException: Cannot cast from source type to destination type.
I took a closer look at LitJson.JsonData. It does have the internal class OrderedDictionaryEnumerator : IDictionaryEnumerator implementation. I am not sure what is missing. Any ideas?
protected static IDictionary<string, object> JsonToDictionary(JsonData in_jsonObj)
{
foreach (KeyValuePair<string, JsonData> child in in_jsonObj)
{
...
}
}
The
LitJson.JsonDataclass is declared as:Where the
IJsonWrapperin turn derives from these two interfaces:System.Collections.IListandSystem.Collections.Specialized.IOrderedDictionary.Note that both of these are the non-generic collection versions. When enumerating you are not going to get a
KeyValuePair<>as the result. Instead, it will be aSystem.Collections.DictionaryEntryinstance.So you will have to change your
foreachto: