igla
igla

Reputation: 115

parse JSON with ServiceStack

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

Answers (2)

L.B
L.B

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

rekire
rekire

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

Related Questions