title: How to read JSON Object Array with Xamarin Android Newtonsoft.Json
body: <p>Hello guys I have an app that I'm trying to get a Json Array response and put it into a TextView, but it has 5 Counts and I don't know how to use a for to read each field of the JsonArray here is the code:</p>
  
  <pre><code>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;
  using Org.Json;
  using System.Net;
  using System.IO;
  using System.Collections.Generic;
  
  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 txtsobrenome;
      RestClient orderId { get; set; }
      RestRequest requestorderId { get; set; }
      IRestResponse answerorder { get; set; }
      TextView txtnome;
      TextView txtorder;
      TextView txtmensagem;
  
      protected override void OnCreate(Bundle bundle)
      {
          base.OnCreate(bundle);
  
          // Set our view from the "main" layout resource
          SetContentView(Resource.Layout.Main);
          btnConsumer = FindViewById&lt;Button&gt;(Resource.Id.btnConsumer);
          edtcpf = FindViewById&lt;EditText&gt;(Resource.Id.edtcpf);
          txtcpf = FindViewById&lt;TextView&gt;(Resource.Id.txtcpf);
          txtsobrenome = FindViewById&lt;TextView&gt;(Resource.Id.txtresposta);
          txtnome = FindViewById&lt;TextView&gt;(Resource.Id.txtNome);
          txtorder = FindViewById&lt;TextView&gt;(Resource.Id.txtorder);
          txtmensagem = FindViewById&lt;TextView&gt;(Resource.Id.txtMensagem);
          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);
              Pessoa pessoa = JsonConvert.DeserializeObject&lt;Pessoa&gt;(mensagemConsumer.Content);
              txtnome.Text = "Nome: " +pessoa.firstName;
              txtsobrenome.Text = "Sobrenome: "+ pessoa.lastName;
  
              // 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);
              var requestToken = JsonConvert.DeserializeObject&lt;RootObject&gt;(answerorder.Content);
              var parse = JObject.Parse(answerorder.Content);
              var QtdeItens = parse.Count;
              var end = "";
              /*foreach (Dictionary&lt;string, Order2&gt; kvp in Order)
              {
                  txtorder.Text = "Id: " + kvp.Value.orderId;
  
              }*/
  
  
          }
          catch (Exception)
          {
  
              throw;
          }
  
  
  
  
      }
  
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I created a class on <a href="http://json2csharp.com/" rel="nofollow noreferrer">http://json2csharp.com/</a> and here is the class that I'm using to get the values. <strong>The JSON answer depoends on the Id number that the person set, so it can be diferent every time I did this test using the ID 181.299.668-32</strong></p>
  
  <pre><code>using System;
  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;
  using Newtonsoft.Json;
  
  public class Order2
  {
  public object orderId { get; set; }
  public string orderStatusCode { get; set; }
  public string orderStatusDescription { get; set; }
  public int serviceProviderId { get; set; }
  public string orderOpeningDate { get; set; }
  public string orderSchedulingDate { get; set; }
  public string orderSchedulingPeriod { get; set; }
  public object orderSettlementDate { get; set; }
  public object orderCancellationDate { get; set; }
  }
  
  public class Order
  {
  public Order2 order { get; set; }
  }
  
     public class RootObject
     {
     public List&lt;Order&gt; orders { get; set; }
     }
  </code></pre>
  
  <p>So the answer that the json returns is : 
  <em>{"orders":[{"order":{"orderId":7004093603,"orderStatusCode":"CANC","orderStatusDescription":"Cancelado","serviceProviderId":3649,"orderOpeningDate":"2015-07-07","orderSchedulingDate":"2015-07-18","orderSchedulingPeriod":"M","orderSettlementDate":null,"orderCancellationDate":null}},{"order":{"orderId":7004153791,"orderStatusCode":"AGEN","orderStatusDescription":"Agendado","serviceProviderId":3524,"orderOpeningDate":"2016-08-31","orderSchedulingDate":"2016-09-01","orderSchedulingPeriod":"M","orderSettlementDate":null,"orderCancellationDate":null}},{"order":{"orderId":7004156972,"orderStatusCode":"ABRT","orderStatusDescription":"Aberto","serviceProviderId":30820,"orderOpeningDate":"2017-04-13","orderSchedulingDate":null,"orderSchedulingPeriod":null,"orderSettlementDate":null,"orderCancellationDate":null}},{"order":{"orderId":7002178478,"orderStatusCode":"CANC","orderStatusDescription":"Cancelado","serviceProviderId":3555,"orderOpeningDate":"2014-02-22","orderSchedulingDate":"2014-02-24","orderSchedulingPeriod":"M","orderSettlementDate":null,"orderCancellationDate":null}},{"order":{"orderId":7002118317,"orderStatusCode":"CANC","orderStatusDescription":"Cancelado","serviceProviderId":3555,"orderOpeningDate":"2014-02-10","orderSchedulingDate":"2014-02-15","orderSchedulingPeriod":"M","orderSettlementDate":null,"orderCancellationDate":null}}]}</em></p>
  
  <p>And JsonViewer said that it has 5 counts, so <strong>how can I do a for or foreach to read the orderId, orderStatus code, orderStatusDescription and orderOpeningDate because dependiing on the Id it has from 0 to 10 counts</strong></p>
  
  <p>[EDIT]</p>
  
  <p>Using the method:</p>
  
  <pre><code>foreach (var order in requestToken.orders)
              {
  
                      object vader = order.order.orderId;
                      string darth = Convert.ToString(vader);
                      txtorder.Text = darth;
                      txtorder.Text = order.order.orderStatusDescription;
                      txtorder.Text = order.order.orderStatusCode.;
                 }
  </code></pre>
  
  <p>It returned one orderId :) . My doubt is: it's calling the <strong>orderId of the count 0 automatically</strong> how can I call the others orderIds? Is it like this?</p>
  
  <pre><code>               foreach (var order in requestToken.orders)
              {
                  //for (var i = 0; i &lt; requestToken.orders.Count; i++)
                  //{
                      object vader = order.order.orderId[1], [2], etc;
                      string darth = Convert.ToString(vader);
                      txtorder.Text = darth;
                      txtorder.Text = order.order.orderStatusDescription;
                      txtorder.Text = order.order.orderStatusCode.;
                  //}
  </code></pre>
  
  <p>Thank you guys for helping me</p>