JsonConvert.DeserializeObject problem

Oct 12, 2009 at 10:25 AM
Edited Oct 12, 2009 at 11:20 AM

Hi

I have the following code and json:

 

{"label": 
[
  ["seq1",1]
  ,["seq2",2]
]}


    public class Labels
    {
        public Labels()
        {}

        public Label[] Label {get;set;}
    }

    public class Label
    {
        public Label()
        { }
        public string Name { get; set; }
        public int TorrentsInLabel { get; set; }
    }
//...
Labels o = JsonConvert.DeserializeObject<Labels>(json);
//...

I would like this array  ["seq1","1"] to deserialize into Label object. What am I missing? Some attributes?

When I run I get exception: Expected a JsonArrayContract for type 'test_JSONNET.Label', got 'Newtonsoft.Json.Serialization.JsonObjectContract'.

tnx

gg

Oct 13, 2009 at 9:02 AM

is this not possible?

Coordinator
Oct 13, 2009 at 9:17 AM

No. Write a JsonConverter for Label if you want it in an array.