0

I have a a api response from Azure Ml which returns the follow json bellow:

responseApi content

{ "Results": { "id_unidade_negocio": [ { "msgSucesso": "Processamento concluído com sucesso" } ] } }

I would like to extract only the "msgSucesso": "Processamento concluído com sucesso"

I try the code below, however didn't work.

var obj = JObject.Parse(responseApi);
var msg = (string)obj.SelectToken("Results.msgSucesso");

I didin't try to deserialize the json to a object class, because I don't know the right format class to create it to be compatible with output json.

Whats is the best way to extract this info from json response? Or How can I create a class that fit in this json output in other to convert the json to object?

2
  • Deserialize it to dynamic if you don't have the class. Commented Apr 3, 2020 at 2:17
  • I tried this alternative as well. It Works. But after the object is created how can I access the atribute that i need ? When I inspect the object all the data are inside the Root parameter. Commented Apr 3, 2020 at 2:30

1 Answer 1

0

https://stackoverflow.com/a/24233127/2906166

check above link

public class IdUnidadeNegocio
{
    public string msgSucesso { get; set; }
}

public class Results
{
    public List<IdUnidadeNegocio> id_unidade_negocio { get; set; }
}

public class RootObject
{
    public Results Results { get; set; }
}


var obj = JsonConvert.DeserializeObject<RootObject>(responseApi);
Console.WriteLine(obj.Results.First().msgSucesso);
Sign up to request clarification or add additional context in comments.

1 Comment

It worked! Creating the class and then converting to a json I was able to extract the information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.