title: Android java parse json from url to object list
body: <p>I would like to connect to a Api url, retrieve the json and store everything in a object list. <a href="http://www.gw2spidy.com/api/v0.9/json/item-search/Sunrise" rel="nofollow">Here is an example</a> of what the url can return as Json. Notice at the beginning there is a <code>count</code>, <code>page</code> and <code>last_page</code>. These are how many items there are on the page, what page you are on and how many pages there are in total (max 50 counts on 1 page). A unspecific search could easily return up to 1000 pages of results</p>
  
  <p>I have this code in c# which works flawlessly but after searching and trying for a long time i have no idea how to recreate this in Android java.</p>
  
  <p>This is api_handler.cs </p>
  
  <pre><code>public class api_Handler
      {
          public static RootObject objFromApi_idToName(string spidyApiUrl, int page){
              RootObject rootObject = null;
              RootObject tempRootObject = null;
  
              do{
                  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(spidyApiUrl + "/" + page);
  
                  WebResponse response = request.GetResponse();
                  using (Stream responseStream = response.GetResponseStream()){
                      StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                      var jsonReader = new JsonTextReader(reader);
                      var serializer = new JsonSerializer();
                      tempRootObject = serializer.Deserialize&lt;RootObject&gt;(jsonReader);
  
                      if (rootObject == null){
                          rootObject = tempRootObject;
                      }
                      else{
                          rootObject.results.AddRange(tempRootObject.results);
                          rootObject.count += tempRootObject.count;
                      }
                  }
                  page++;
              }
  
              while (tempRootObject != null &amp;&amp; tempRootObject.last_page != tempRootObject.page);
              return rootObject;
          }
  }
  </code></pre>
  
  <p>Which i called in the main_form.cs like this</p>
  
  <pre><code>// url will become = http://www.gw2spidy.com/api/v0.9/json/item-search/ + textbox.text
  // full example = http://www.gw2spidy.com/api/v0.9/json/item-search/Sunrise
      string spidyApiUrl = String.Format("{0}{1}/api/{2}/{3}/{4}/{5}", Http, spidyHost, spidyApiVersion, format, spidyApiType, dataId);
      var spidyApi_idByName = api_Handler.objFromApi_idToName(spidyApiUrl, startPage);
  </code></pre>
  
  <p>And ofcourse the constructors though I would assume these arent really important to include in the question.</p>
  
  <pre><code>public class Result
      {
          public int data_id { get; set; }
          public string name { get; set; }
          public int rarity { get; set; }
          public int restriction_level { get; set; }
          public string img { get; set; }
          public int type_id { get; set; }
          public int sub_type_id { get; set; }
          public string price_last_changed { get; set; }
          public int max_offer_unit_price { get; set; }
          public int min_sale_unit_price { get; set; }
          public int offer_availability { get; set; }
          public int sale_availability { get; set; }
          public int sale_price_change_last_hour { get; set; }
          public int offer_price_change_last_hour { get; set; }
      }
  
      public class RootObject
      {
          public int count { get; set; }
          public int page { get; set; }
          public int last_page { get; set; }
          public int total { get; set; }
          public List&lt;Result&gt; results { get; set; }
      }
  </code></pre>
  
  <p>How can i turn this working code in c# to android java? Or is it a better idea to start all over from scratch (i would still require some guidance as i have tried quite few times without success)</p>
  
  <p><strong>Also:</strong></p>
  
  <p>in C# on a pc this would run in a perfect acceptable time maybe load 1-2 sec for a 1000x50 objects which is a very unspecific search. These unspecific searches can ofcourse happen since its determined from user input but it wont happen too often, a normal search could be from 1 page to 50. is a phonecapable of doing this in a acceptable time?</p>
  
  <p><strong>TL;DR</strong>
  Connect to api > retrieve all json values > store all in object list > send back to activity.java</p>