I'm starting development and I'm in need of help. I got this Json I'm getting from the bank. However I need to filter the information by name for my method to return. For example. If the name="Percent Processor Time", it should only return the array of values attached to it.
[
{
"name": "Percent Processor Time",
"jsonValues": [
{
"time": "2018-01-22T18:10:30Z",
"instanceName": "RD00155D00C625",
"value": 15.3125
}
]
},
{
"name": "Requests per Sec",
"jsonValues": [
{
"time": "2018-01-22T18:10:30Z",
"instanceName": "RD00155D00C625",
"value": 8.5666666666666664
}
]
},
{
"name": "Handles",
"jsonValues": [
{
"time": "2018-01-22T18:11:00Z",
"instanceName": "RD00155D00C625",
"value": 2221.0
}
]
},
{
"name": "Threads",
"jsonValues": [
{
"time": "2018-01-22T18:11:00Z",
"instanceName": "RD00155D00C625",
"value": 69.0
}
]
},
My method is as follows.
public List<JsonValue> GetPerformance(DateTime StartDate, DateTime EndDate, string Name)
{
var db = new Core.Database.EntitiesContext();
var performance = new PerformanceInfo();
performance.MarkTraceDates();
List<JsonValue> retorno = null;//Criando lista para armazenar dados
try
{
var resultSearch = db.Performances.OrderByDescending(x => x.CreatedDate).First();//buscando no banco
retorno = JsonConvert.DeserializeObject<List<JsonValue>>(resultSearch.Json);//deserializando Json na lista
}
catch (Exception e)
{
Console.Write(e.Message);
}
List<JsonValue> filtrado = new List<JsonValue>();
filtrado = retorno.Select(x => new JsonValue
{
Name = x.Name,
JsonValues = x.Properties.Data.Values.Select(y => new JsonValues { InstanceName = y.InstanceName, Time = y.Time, Value = y.Value }).ToList()
}).ToList();
Can anyone help me?