2

I would like to deserialize the following json using DataContractJsonSerializer:

 "coordinates": [
                           [
                               18.008966033966707,
                               59.328701014313964
                           ],
                           [
                               18.008642062225096,
                               59.3283087435048
                           ]
                       ]

Since the items in the array does not have a name I don't know how to tell the DataContractJsonSerializer what the items are. I have tried:

[DataContract]
public  class Coordinate :IExtensibleDataObject
{

    [DataMember(Order = 1)]
    public decimal Longitude { get; set; }

    [DataMember(Order = 2)]
    public decimal Latitude { get; set; }

    public ExtensionDataObject ExtensionData { get; set; }
}

Any ideas?

dbc
  • 104,963
  • 20
  • 228
  • 340
Per Kastman
  • 4,466
  • 24
  • 21

1 Answers1

2

Found out how to do this. The following code solves the problem:

[CollectionDataContract] 
public  class Coordinate : List<object> 
{ 
    public decimal Longitude { get { return (decimal)this[0]; } set { this[0] = value; } } 

    public decimal Latitude { get { return (decimal)this[1]; } set { this[1] = value; } } 

    public ExtensionDataObject ExtensionData { get; set; } 
} 
Per Kastman
  • 4,466
  • 24
  • 21
  • 1
    I think your setter for `Latitude` is wrong. It should use `this[1]`, just like the getter. – svick Mar 17 '12 at 14:09