Login (JSON)
string url = serviceUrl + "rest/login";
string responseString = null;
//string contentType = "application/x-www-form-urlencoded";
//string postData = "UserName=" + accountID + "&Password=" + password;
string contentType = null;
string postData = null;
if (radioBtnJson.Checked)
{
contentType = "text/json";//or application/json
postData = "{\"UserName\":\"" + accountID + "\",\"Password\":\"" + password + "\"}";
responseString = CallService(url, postData, contentType);
//Parse login result
JavaScriptSerializer json = new JavaScriptSerializer();
Dictionary data = json.Deserialize>(responseString);
if ((string)data["Message"] == "Success")
{
this.key = (string)data["Key"];
}
// There is another way to deserialize login result.
// We can create object LoginResult and pass as generic type in json.Deserialize<>() method.
// For example: LoginResult result = json.Deserialize(responseString);
// and then we can use properties of the result variable:
// if(result.Status=="Success")
// {
// this.key = result.Key;
// }