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.JsonData
class is declared as:Where the
IJsonWrapper
in turn derives from these two interfaces:System.Collections.IList
andSystem.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.DictionaryEntry
instance.So you will have to change your
foreach
to: