2
A question. Before the service returned values in the following signature: Planned/Accomplished, This made it much easier. Now the subscription has changed to this:
{
"CorIndicador":"VERMELHO",
"DadosIndicador":"{\"Previsto\":25784.686452608872,\"Realizado\":95258.9557949728}",
"TipoIndicador":1
}
with the previous signature the class Indicadoritem that was so:
public string Nome { get; set; }
public decimal Valor { get; set; }
now with the new signature, as entered two new fields Chorister and Tipoindicator. How I would do to popular the class?
public class IndicadorData : List<IndicadorItem>
{}
so I de-realize
var resp = JsonConvert.DeserializeObject<KpiResponse>(response.Content);
this is the Kpi class
[DataContract]
public class KpiResponse
{
[DataMember]
public TipoIndicador TipoIndicador { get; set; }
[DataMember]
public string CorIndicador { get; set; }
[DataMember]
public string DadosIndicador { get; set; }
}
after deserealizar in the kpi class, I do so to catch the Data
var fat = JsonConvert.DeserializeObject<FaturamentoResponse>(resp.DadosIndicador);
that’s the class Billing response
public class FaturamentoResponse
{
public double Previsto { get; set; }
public double Realizado { get; set; }
}
That’s exactly what I have. What should I do in this case to popular this class(Indicadoritem)? The way it is does not work. Which way to do it?
EDIT1
I changed the Indicadordata class by adding the Index field and at the time of consuming the Service, switch..case
i do it:
var fat = JsonConvert.DeserializeObject<FaturamentoResponse>(resp.DadosIndicador);
res.CorIndicador = resp.CorIndicador;
res.Add(new IndicadorItem { Nome = "Realizado", Valor = Convert.ToDecimal(fat.Realizado) });
res.Add(new IndicadorItem { Nome = "Previsto", Valor = Convert.ToDecimal(fat.Previsto) });
This Json is just that, or is it a list of that? if it’s a list put the example in the question!
– novic
@Virgilionovic, that’s just the json. It comes that way, it only varies the values, but that’s just.
– pnet
You want an example to consume this
json
?– novic