I want to get the first or default element of jArray into an object
{[
{
"timex": "XXXX-08-25",
"type": "date",
"value": "2016-08-25"
},
{
"timex": "XXXX-08-25",
"type": "date",
"value": "2017-08-25"
}
]}
(This array can be different by the next call) How can I get the value of "value" from the first element in an object with linq? This: "2016-08-25"
Your json seems not valid, because it's starts with "{[". On valid JSON input you can use this code:
var input = "[ { \"timex\": \"XXXX-08-25\",\r\n \"type\": \"date\",\r\n \"va2lue\": \"2016-08-25\"\r\n },\r\n {\r\n \"timex\": \"XXXX-08-25\",\r\n \"type\": \"date\",\r\n \"value\": \"2017-08-25\"\r\n }\r\n]";
var jArray = JArray.Parse(input);
var result = jArray.FirstOrDefault()?["value"]?.Value<DateTime>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With