Search Unity

Dictionary with multiple types

Discussion in 'Scripting' started by elpuerco63, Mar 13, 2017.

  1. elpuerco63

    elpuerco63

    Joined:
    Jun 26, 2014
    Posts:
    271
    I'm struggling to get my head around being able to declare an dictionary that has the structure below.

    The top level would be Dictionary<string, ArrayList> but how do I declare the dictionary within the array that itself has an array?

    {
    "ParentArray":[
    {
    "a key":"any text",
    "another key":"any text",
    "yet another key":"any text",
    "ChildArray":[
    {
    "a key":"any text",
    "another key":"any text"
    }
    ]
    }
    ]
    }
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Don't use ArrayList (or any untyped collection for that matter).

    Declare a custom data class that has everything you need.
    Code (csharp):
    1.  
    2. public class SomeClass
    3. {
    4.     Dictionary<string, string> childArray;
    5. }
    6.  
    7. Dictionary<string, SomeClass> parentArray;
    8.  
     
    elpuerco63 likes this.
  3. elpuerco63

    elpuerco63

    Joined:
    Jun 26, 2014
    Posts:
    271
    The saying can't see the wood for the trees comes to mind!!! Thanks man :)