0

I have some data in the following format. There's a uuid with timeseries reading, each tuple representing a timestamp and value.

"[{\"uuid\": \"3c24a849-3355-5b28-bf83-1e93c36eea75\", \"Readings\": [[1541524171000.0, 22.700000762939453], [1541531370000.0, 22.600000381469727], [1541577227000.0, 21.700000762939453], [1541578016000.0, 21.899999618530273], [1541578322000.0, 22.100000381469727], [1541580122000.0, 22.0]]}]"

This is a response from a rest service that's meant to return json. I went ahead and did

public class DataReading
{
    public string uuid { get; set; }
    public string readings { get; set; }
}

imported Newtonsoft.Json and did

var list = JsonConvert.DeserializeObject<List<DataReading>>(thereturnstring);

I'm getting an error

Newtonsoft.Json.JsonReaderException: 'Unexpected character encountered while parsing value: [. Path '[0].Readings', line 1, position 63.'

Any insight? Line 1 position 63 seems to be the 'n' in Readings. How do I convert this to anything meaningful?

Ehrendil
  • 233
  • 3
  • 13

1 Answers1

0

Change your class from:

public class DataReading
{
    public string uuid { get; set; }
    public string readings { get; set; }
}

to

public class DataReading
{
    public string uuid { get; set; }
    public double[][] readings { get; set; }
}

Then you can Deserialize it like:

string jsonString = "[{\"uuid\": \"3c24a849-3355-5b28-bf83-1e93c36eea75\", \"Readings\": [[1541524171000.0, 22.700000762939453], [1541531370000.0, 22.600000381469727], [1541577227000.0, 21.700000762939453], [1541578016000.0, 21.899999618530273], [1541578322000.0, 22.100000381469727], [1541580122000.0, 22.0]]}]";
var result = Newtonsoft.Json.JsonConvert.DeserializeObject<DataReading[]>(jsonString);

Live Demo

Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171