Ir ao conteúdo
  • Cadastre-se

Lucas Moreira dos Santos

Membro Júnior
  • Posts

    1
  • Cadastrado em

  • Última visita

Reputação

0
  1. Olá estou criando um aplicativo usando o Xamarin.Android, a resposta Json que obtenho ao chamar a API é essa: {"consumerId":56704292158, "categoryId":1, "categoryDescription": "Pessoa", "firstName":"Ronaldo","lastName":"Scalizi Pecanha","fiscalDocuments":[{"fiscalDocument":{"documentType":"Brasil: nº CPF","cpf":18825966832}}],"gender":"M","emailAddress":"[email protected]","optIns":[{"optIn":{"brandName":"consul","acceptanceStatus":false}},{"optIn":{"brandName":"brastemp","acceptanceStatus":true}}],"communicationData":[{"communicationInfo":{"addressId":26506503,"phoneNumbers":[{"phoneNumber":{"phoneType":"mobilePhone","phoneNumber":1195099038}}],"streetAddress":"AVENIDA RANGEL PESTANA","streetNumber":674,"streetComplement":null,"streetDistrict":"JARDIM CRISTIANE","cityName":"SANTO ANDRE","stateCode":"SP","zipCode":"09185220","locationReferences":[{"locationReference":"Mercado"}],"countryCode":"BR"}},{"communicationInfo":{"addressId":2.563244E+7,"phoneNumbers":[{"phoneNumber":{"phoneType":"mobilePhone","phoneNumber":11960625256}},{"phoneNumber":{"phoneType":"homePhone","phoneNumber":1143199038}}],"streetAddress":"AVENIDA RANGEL PESTANA","streetNumber":674,"streetComplement":"CASA","streetDistrict":"JARDIM CRISTIANE","cityName":"SANTO ANDRE","stateCode":"SP","zipCode":"09185220","locationReferences":[{"locationReference":"Ao lado do deposito lua nova"}],"countryCode":"BR"}}]} Eu só preciso inserir em um campo textview os campos firstName e lastName, aqui está o código que estou usando: using System; using System; using Android.App; using Android.Widget; using Android.OS; using RestSharp; using Newtonsoft.Json; using Android.Util; using App4.Resources; using Newtonsoft.Json.Linq; namespace App4 { [Activity(Label = "App4", MainLauncher = true, Icon = "@drawable/icon")] public class MainActivity : Activity { EditText edtcpf; Button btnConsumer; TextView txtcpf; RestRequest cpf { get; set; } public RestClient consumer { get; set; } IRestResponse mensagemConsumer; TextView txtresposta; RestClient orderId { get; set; } RestRequest requestorderId { get; set; } IRestResponse answer { get; set; } IRestResponse answerorder { get; set; } TextView txtnome; public string raika; private string teamname; private JToken primeironome; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); btnConsumer = FindViewById<Button>(Resource.Id.btnConsumer); edtcpf = FindViewById<EditText>(Resource.Id.edtcpf); txtcpf = FindViewById<TextView>(Resource.Id.txtcpf); txtresposta = FindViewById<TextView>(Resource.Id.txtresposta); txtnome = FindViewById<TextView>(Resource.Id.txtNome); btnConsumer.Click += BtnConsumer_Click; } private void BtnConsumer_Click(object sender, EventArgs e) { try { // API Consumer CPF consumer = new RestClient("https://qa.api-latam.whirlpool.com/v1.0/consumers"); cpf = new RestRequest("/" + edtcpf.Text, Method.GET); cpf.AddHeader("Content-Type", "application/json; charset=utf-8"); cpf.AddHeader("Authorization", "Bearer 70197e6c-d81b-384c-bb32-d69e8c10b101"); mensagemConsumer = consumer.Execute(cpf); string nombre = Convert.ToString(mensagemConsumer.Content); Nome nome = new Nome(); string json = JsonConvert.SerializeObject(mensagemConsumer.Content, Formatting.Indented); nome.firstName = mensagemConsumer.Content; Log.Info("info ",json); txtresposta.Text = json; //API Consumer Appliances orderId = new RestClient("https://qa.api-latam.whirlpool.com/v1.0/consumers/"); requestorderId = new RestRequest("/"+ edtcpf.Text+ "/service-orders", Method.GET); requestorderId.AddHeader("Content-Type", "application/json; charset=utf-8"); requestorderId.AddHeader("Authorization", "Bearer 70197e6c-d81b-384c-bb32-d69e8c10b101"); answerorder = orderId.Execute(requestorderId); txtnome.Text = answerorder.Content; string respostaorder = Convert.ToString(answerorder); dynamic deserializado = JsonConvert.DeserializeObject(respostaorder); } catch (Exception) { throw; } } } } Aqui é a classe que criei para usar como base de programa using System.Collections.Generic; using System.Linq; using System.Text; using Android.App; using Android.Content; using Android.OS; using Android.Runtime; using Android.Views; using Android.Widget; namespace App4.Resources { public class Nome { public string firstName { get; set;} public string lastName { get; set; } } } Como posso pegar apenas esses campos usando o serialize e o Deserialize?

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

 

GRÁTIS: ebook Redes Wi-Fi – 2ª Edição

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!