Reputation: 115
How to parse this json string? I tried to put in in Dictionary
var dictionary = text.FromJson<Dictionary<string, string>>();
but the array is not parsed.
{"v":[[9,-1],[9,-44,1]]}
Upvotes: 3
Views: 2248
Reputation: 116098
try this class
public class Root
{
public List<List<int>> v;
}
var result = text.FromJson<Root>();
EDIT
Since your json string has changed, I prepared a sample using Json.Net
string json = @"{ v: [ [ 9, 16929, 1, 856, 128, '123', 'hello', {'type': 'photo', 'attach1': '123_456'} ] ] } ";
var obj = (JObject)JsonConvert.DeserializeObject(json);
foreach (var arr in obj["v"])
{
foreach(var item in arr)
{
if (item is JValue)
{
Console.WriteLine(item);
}
else
{
Console.WriteLine(">>> " + item["type"]);
}
}
}
Upvotes: 3
Reputation: 47945
You use the wrong structure. You value is a multi demensional array and no string. Try the type
Dictionary<String, List<List<int>>>
var dictionary = text.FromJson< Dictionary<String, List<List<int>>>>();
Upvotes: 3