title: Call ASP.NET webmethod from iOS and JSON parse
body: <p>I have an <code>.aspx</code> file with some webmethods inside. I want to consume those methods from inside an iOS (iPhone) Application.
  The webmethod code is as follows:</p>
  
  <pre><code>[WebMethod]
  public static string Login(string username, string password) 
  {
      return username + ":" + password;
  }
  </code></pre>
  
  <p>To test this webmethod I used:</p>
  
  <pre><code>$.ajax({
      type: "POST",
      url: "DataProvider.aspx/Login",
      data: JSON.stringify({ username: "myUserName", password: "myPassword" }),
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function (result) { alert(result.d); },
      error: function (xhr, ajaxOptions, thrownError) {
          alert(xhr.status);
          alert(thrownError);
      }
  });
  </code></pre>
  
  <p>So everything checks out and I get <code>"myUserName:myPassword"</code> back, now I want to do the same from inside xcode 4.5.2, so I created a new iPhone app and place a <code>label</code> (lbResult) and a <code>button</code> (btDoLogin) inside the ViewController and assigned the outlet and action.</p>
  
  <p>Note that I'm not interested in async or delegates, I just want the data back and be able to parse it (JSON).</p>
  
  <p>Sorry for being so specific about the details, but I saw a lot of similar questions and none of the answers worked for me. For what I read it's my understanding that this can be solved using NSURLConnection. For example, this question <a href="https://stackoverflow.com/questions/9968042/passing-parameters-to-a-json-web-service-in-objective-c">Passing parameters to a JSON web service in Objective C</a> is very similar to what I need, but what I get back is the entire page! (meaning it's downloading the entire page instead of calling the web method) Also, I need to pass 2 parameters and the question uses only 1 (and I don't understand how to separate them in the concatenated string).</p>
  
  <p>Now, what exactly do I need to out inside the IBAction to connect to this particular webmethod and get the return value?</p>
  
  <pre><code>- (IBAction)btDoLogin:(id)sender {
      // magic code goes here!
  }
  </code></pre>
  
  <p>Thanks.-</p>