I have a return in Json and I want to get the data in C# (CNPJ Data)

Asked

Viewed 194 times

-2

I have a link that I pass the CNPJ (https://www.receitaws.com.br/v1/cnpj/@cnpj) and it returns me a json with all the information, what is my doubt, how do I take this information as Social Reason, Name Fantazia, Address and Insert them in the textbox of the Application? I’ve tried a few things and I honestly can’t get out of place, they can help me?

I made an example that was passed on a site, I can even capture the whole result, but I can’t get the data inside that result:

var client = new Webclient(); var conteudo = client.Downloadstring("https://www.receitaws.com.br/v1/cnpj/@cnpj".Replace("@cnpj", txtCNPJ.Text));

Thank you.

  • Post your code so we can help you

  • Xmldocument doc = new Xmldocument(); Dataset ds = new Dataset(); var client = new Webclient(); var contents = client.Downloadstring("https://www.receitaws.com.br/v1/cnpj/@cnpj".Replace("@cnpj", txtCNPJ.Text); string on = content; Xnode Node = Jsonconvert.Deserializexnode(json, "Root"); string xml = Node.Tostring();ds.Readxml(xml); string check = ds. Tables[0]. Rows[0]["Result"]. Tostring(); if (verify == "1") { txtEndereco.Text = ds.Tables[0]. Rows[0]["street"]. Tostring(); }

  • Just to understand you can get the data in the right xml format, and want to convert it to json is this ?

  • Come on, I get the Json data already but do not know how to take the result and play inside the system Textbox, in case you take the "Address" of the json and play in the textbox Address of the system understand? type separate the data to put in its places on the screen

1 answer

0

Try to deserialize the json object you receive Jsonconvert.Deserializeobject from the Newtonsoft namespace.Json. Link Newtonsoft.

You will basically get your json and convert it to a c#class or Object, and use it normally in your program.

//Passando um tipo de referencia
//conteudo é seu json
var meuObjConvertido = JsonConvert.DeserializeObject<SuaClasse>(conteudo);

//ou
var meuObjConvertido = JsonConvert.DeserializeObject(conteudo); //Retorna um object

Browser other questions tagged

You are not signed in. Login or sign up in order to post.