title: How to handle data from httpclient
body: <p>I'm working on a new Windows Phone 8 app. I'm connecting to a webservice which returns valid json data. I'm using longlistselector to display the data. This works fine when i'm using the string json in GetAccountList(); but when receiving data from the DataServices class i'm getting the error "Cannot implicitly convert type 'System.Threading.Tasks.Task'to string". Don't know what goes wrong. Any help is welcome. Thanks!</p>
  
  <p><strong>DataServices.cs</strong></p>
  
  <pre><code>    public async static Task&lt;string&gt; GetRequest(string url)
      {
          HttpClient httpClient = new HttpClient();
  
          await Task.Delay(250);
  
          HttpResponseMessage response = await httpClient.GetAsync(url);
          response.EnsureSuccessStatusCode();
          string responseBody = await response.Content.ReadAsStringAsync();
          Debug.WriteLine(responseBody);
          return await Task.Run(() =&gt; responseBody);
      }
  </code></pre>
  
  <p><strong>AccountViewModel.cs</strong></p>
  
  <pre><code> public static List&lt;AccountModel&gt; GetAccountList()
      {
          string json = DataService.GetRequest(url);
          //string json = @"{'accounts': [{'id': 1,'created': '2013-10-03T16:17:13+0200','name': 'account1 - test'},{'id': 2,'created': '2013-10-03T16:18:08+0200','name': 'account2'},{'id': 3,'created': '2013-10-04T13:23:23+0200','name': 'account3'}]}";
          List&lt;AccountModel&gt; accountList = new List&lt;AccountModel&gt;();
  
          var deserialized = JsonConvert.DeserializeObject&lt;IDictionary&lt;string, JArray&gt;&gt;(json);
  
          JArray recordList = deserialized["accounts"];
  
  
          foreach (JObject record in recordList)
          {
              accountList.Add(new AccountModel(record["name"].ToString(), record["id"].ToString()));
          }
  
          return accountList;
      }
  </code></pre>
  
  <p><strong>UPDATE:</strong> I changed it slightly and works like a charm now. Thanks for your help!
  DataServices.cs</p>
  
  <pre><code>     //GET REQUEST
      public async static Task&lt;string&gt; GetAsync(string url)
      {
          var httpClient = new HttpClient();
  
          var response = await httpClient.GetAsync(url);
  
          string content = await response.Content.ReadAsStringAsync();
  
          return content;
      }
  </code></pre>
  
  <p>AccountViewModel.cs</p>
  
  <pre><code>    public async void LoadData()
      {
          this.Json = await DataService.GetAsync(url);
          this.Accounts = GetAccounts(Json);
          this.AccountList = GetAccountList(Accounts);
          this.IsDataLoaded = true;
      }
  
      public static IList&lt;AccountModel&gt; GetAccounts(string json)
      {
          dynamic context = JObject.Parse(json);
  
          JArray deserialized = (JArray)JsonConvert.DeserializeObject(context.results.ToString());
  
          IList&lt;AccountModel&gt; accounts = deserialized.ToObject&lt;IList&lt;AccountModel&gt;&gt;();
  
          return accounts;
      }
  
      public static List&lt;AlphaKeyGroup&lt;AccountModel&gt;&gt; GetAccountList(IList&lt;AccountModel&gt; Accounts)
      {
          List&lt;AlphaKeyGroup&lt;AccountModel&gt;&gt; accountList = AlphaKeyGroup&lt;AccountModel&gt;.CreateGroups(Accounts,
                  System.Threading.Thread.CurrentThread.CurrentUICulture,
                  (AccountModel s) =&gt; { return s.Name; }, true);
  
          return accountList;
      }
  </code></pre>