2
Good morning folks! I’m new to C# and I’m having a hard time picking up a value within a complex Json. This is Json:
{
"id": "58e50b82-50b1-4f29-a2e8-a9a544013255",
"timestamp": "2018-06-20T18:00:12.935Z",
"lang": "pt-br",
"result": {
"source": "agent",
"resolvedQuery": "me conte uma novidade",
"action": "",
"actionIncomplete": false,
"parameters": {
"news": "novidade"
}
}
So far I can collect only the first 3 Json data (id, timestamp and lang) with the following code:
API class:
[HttpPost]
[Route("consumindoApi")]
public HttpResponseMessage DirecionarResposta(Dialogflow dialogflow)
{
try
{
return Request.CreateResponse(HttpStatusCode.OK,
@"ID: " + dialogflow.id +
". Idioma: " + dialogflow.lang +
". ID da Sessão: " + dialogflow.sessionId +
". Horario da mensagem: " + dialogflow.timestamp);
}
catch (Exception e)
{
return Request.CreateResponse(HttpStatusCode.BadRequest, e.Message);
}
}
Model class I use to map Json:
public class Dialogflow
{
public string id { get; set; }
public string timestamp { get; set; }
public string lang { get; set; }
public string sessionId { get; set; }
public string result { get; set; }
}
I use Newtonsoft to do this manipulation, but since I’m new to the piece, I can’t collect the data inside the list result
and parameters
.
How would I manage to collect the values of the fields within these two lists?
You must create another object to
result
.– Marconi