title: Convert json string into multidimensional array
body: <p>This is currently my jSON array:</p>
  
  <pre><code>{"1": [{"11": [[1, 1],[2, 2],[3, 3]],"21": [[1, 1],[2, 2],[3, 3]],"31": [[1, 1],[2, 2],[3, 3]]}],"4": [{"12": [[1, 1],[2, 2],[3, 3]],"22": [[1, 1],[2, 2],[3, 3]],"32": [[1, 1],[2, 2],[3, 3]]}],"6": [{"13": [[1, 1],[2, 2],[3, 3]],"23": [[1, 1],[2, 2],[3, 3]],"33": [[1, 1],[2, 2],[3, 3]]}]}
  </code></pre>
  
  <p>I want to convert this into <code>Dictionary&lt;int, Dictionary&lt;int, Dictionary&lt;int, int&gt;&gt;&gt;</code></p>
  
  <p>I have search for a long long time but couldn't find a possible solution. Until now, I had:</p>
  
  <pre><code>Dictionary&lt;int, Dictionary&lt;int, Dictionary&lt;int, int&gt;&gt;&gt; menus = new Dictionary&lt;int, Dictionary&lt;int, Dictionary&lt;int, int&gt;&gt;&gt;();
  
          JToken entireJson = JToken.Parse(rawDirectory);
  
          foreach (var item in entireJson.Children())
          {
              var property = item as JProperty;
              var subArray = new Dictionary&lt;int, Dictionary&lt;int, int&gt;&gt;();
              foreach (var subItem in property.Value.Children())
              {
                  var subProperty = subItem as JProperty;
                  var subSubArray = new Dictionary&lt;int, int&gt;();
                  foreach (var subSubItem in subItem)
                  {
                      var subSubProperty = subSubItem as JProperty;
                      subSubArray.Add(int.Parse(subSubProperty.Name), int.Parse((String)subSubProperty.Value));
                  }
                  subArray.Add(int.Parse(subProperty.Name), subSubArray);
              }
              menus.Add(int.Parse(property.Name), subArray);
          }
  </code></pre>
  
  <p><strong>Edit - Solution</strong></p>
  
  <p>To generate a <code>Dictionary&lt;&gt;</code> as I want, I have to change the jSON array a bit. When you use brackets <code>[]</code> it creates a <code>List&lt;&gt;</code>. When you use curly brackets you can generate a <code>Dictionary&lt;&gt;</code>.</p>
  
  <p>I have resolved my problem by changing the jSON string to:</p>
  
  <pre><code>{"1": {"11": {"1": 1,"2": 2,"3": 3},"21": {"1": 1,"2": 2,"3": 3},"31": {"1": 1,"2": 2,"3": 3}},"4": {"12": {"1": 1,"2": 2,"3": 3},"22": {"1": 1,"2": 2,"3": 3},"32": {"1": 1,"2": 2,"3": 3}},"6": {"13": {"1": 1,"2": 2,"3": 3},"23": {"1": 1,"2": 2,"3": 3},"33": {"1": 1,"2": 2,"3": 3}}}
  </code></pre>
  
  <p>And used the following code to deserialize:</p>
  
  <pre><code>JsonConvert.DeserializeObject &lt; Dictionary&lt;int, Dictionary&lt;int, Dictionary&lt;int, int&gt;&gt;&gt;&gt;(jSONString)
  </code></pre>
  
  <p>This is how I generate my three dimensional array:</p>
  
  <pre><code>"{" + string.Join(",", dict.Select(a =&gt; String.Format("\"{0}\": {1}", a.Key, String.Join(",", "{" + String.Join(",", a.Value.Select(b =&gt; String.Format("\"{0}\": {1}", b.Key, String.Join(",", "{" + String.Join(",", b.Value.Select(c =&gt; String.Format("\"{0}\": {1}", c.Key, String.Join(",", c.Value)))) + "}")))) + "}")))) + "}"
  </code></pre>