Answer the question
In order to leave comments, you need to log in
C#. json. How to get array elements from an array?
json file
{
"ts":123456,
"pts":123,
"updates":
}
string json = "{\"ts\":1645337136,\"pts\":105,\"updates\":}\r\n";
using System;
using Newtonsoft.Json;
class Events
{
public string ts { get; set; }
public string pts { get; set; }
}
static void Main(string[] args)
{
string json = ""{\"ts\":123456,\"pts\":123,\"updates\":}\r\n";
Events events = JsonConvert.DeserializeObject<Events>(json);
}
Answer the question
In order to leave comments, you need to log in
class Events
{
public string ts { get; set; }
public string pts { get; set; }
public object[][] updates {get;set;}
}
...
Events events = JsonConvert.DeserializeObject<Events>(json);
var first = events.updates.FirstOrDefault(f=>f!=null&&f[0]=="First");//получение первого массива содержащего слово "First"
var text = events.updates.FirstOrDefault(f=>!(f!=null&&f.Any(a=>a=="Text")))//получение массива в котором есть "Text"
if(text==null)
throw new ArgumentException(...);
var textIndex = text.TakeWhile(w=>!(w=="Text")).Count();//получение индекса в массиве для слова "Text"
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question