Type inference when reading from json file in C#

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CrayonApe

Hi guys, I recently made a variant of type Array<Array<Dictionary>> and stored some data in it. Later I saved the data in a file and when I read back the data, the data was of type Array but I couldn’t cast the type to Array<Array<Dictionary>>.

=====

Pseudo-code:

class demo { 
    private Array<Array<Dictionary>> arr;

    public void method() {
        arr = some data;
        ...
        file.write(JSON.Print(arr));
        ...
        content = file.read();
        //result is of type Array
        result = JSON.Parse(content).Result;
        //crash, InvalidCastException
        arr = (Array<Array<Dictionary>>)result;
    }
}

I have tried a few things,

Array arr;
arr = result.Result;
((Array)arr[index])[index] = foo;

seems to be a workaround.

But can I directly cast via like arr = (Array<Array<Dictionary>>)result; ?