1

I was not able to retrieve my api key and user id. I used the Console.WriteLine to check my values, and they were just empty. Shouldn't I be able to retrieve those values?

var client = new RestClient("http://myproject/");
                var request = new RestRequest("api/ApiKey?email=" + email + "&password=" + password, Method.GET);

                var queryResult = client.Execute(request);

                if (queryResult.StatusCode == HttpStatusCode.OK)
                {
                    var deserial = new JsonDeserializer();
                    var x = deserial.Deserialize<ApiKey>(queryResult);

                    Application.Current.Properties["ApiKey"] = x.UserApiKey;
                    Application.Current.Properties ["UserId"] = x.UserId;

                    Console.WriteLine ("here");
                    Console.WriteLine ("key:"+x.UserApiKey);
                    //do this
                }
                else
                {
                    // do this

                }
2
  • did you check queryResult.Content in debug? what does it hold? Commented May 3, 2015 at 12:10
  • @Omribitan : Yes and it holds: {"ApiKey":"rY88liT/BE98t2e3SLXnCQ==","UserId":1} Commented May 3, 2015 at 12:12

1 Answer 1

2

If queryResult.Content holds the following json structure:

 {
     "ApiKey":"rY88liT/BE98t2e3SLXnCQ==",
     "UserId":1
 }

The object you are deserializing to should look like this:

public class ApiKeyOjbect
{
     public string ApiKey { get; set; }
     public string UserId { get; set; }
}

And an esier way to do it would be to serialize the result directly

var queryResult = client.Execute<ApiKeyOjbect>(request);
Sign up to request clarification or add additional context in comments.

2 Comments

name of the class and data field ApiKey is same?
@AabiRegmi no, my mistake. fixed it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.