1
json="{\n \"kind\": \"plus#person\",
    \n \"etag\": \"\\\"GjejyguyfTE/pdfBI8xyufoiuh9bOLZ8VyG_8\\\"\",
    \n \"gender\": \"male\",
    \n \"emails\": [\n  {\n   \"value\": \"[email protected]\",\n   \"type\": \"account\"\n  }\n ],
    \n \"objectType\": \"person\",
    \n \"id\": \"xxxxxxxxxxxxxxx\",
    \n \"displayName\": \"XXXXXXXXX XXXXXXX\",
    \n \"name\": {\n  \"familyName\": \"XXXXXX\",\n  \"givenName\": \"XXXXXX\"\n },
    \n \"url\": \"https://plus.google.com/xxxxxxxxxxxxxxx\",
    \n \"image\": {\n  \"url\": \"https://lh3.googleusercontent.com/-XdUWA/AAAAAAI/AAbbbbAA/42hhscbv5M/photo.jpg?sz=70\"\n },
    \n \"isPlusUser\": true,
    \n \"language\": \"en\",
    \n \"ageRange\": {\n  \"min\": 21\n },
    \n \"circledByCount\": 0,
    \n \"verified\": false\n}\n"



 public class GoogleUser
    {
        public string kind { get; set; }
        public string etag { get; set; }
        public string gender { get; set; }
        public Email[] emails { get; set; }
        public string objectType { get; set; }
        public string id { get; set; }
        public string displayName { get; set; }
        public Name name { get; set; }
        public string url { get; set; }
        public Image image { get; set; }
        public bool isPlusUser { get; set; }
        public string language { get; set; }
        public AgeRange ageRange { get; set; }
        public int circledByCount { get; set; }
        public bool verified { get; set; }
    }

    public class Name
    {
        public string familyName { get; set; }
        public string givenName { get; set; }
    }

    public class Email
    {
        public string value { get; set; }
        public string type { get; set; }
    }
    public class Image 
    {
        public string url { get; set; } 
    }
    public class AgeRange 
    {
        public int min { get; set; }
    }





GoogleUser  user = new JavaScriptSerializer().Deserialize<GoogleUser>(json);

I am developing in C# 4.0 I use login with google+ button in my project. I would like to get user's by using access_token. I can get them as json filen. Then I would like to copy them my GoogleUser class. I don't get error, But user always equal null. By this way, yesterday I could get user's data, but not today.

What can be my problem ?

<code>string a</code> is not <code>null</code>, it is my <code>json</code> file, but <code>user</code> is <code>null</code>

6
  • The code you posted seems to work... Commented Apr 1, 2014 at 12:15
  • First thing; browser is probably caching the request / data and screwing things up (chrome is good at screwing up javascript caching) and secondly; I would use the JsonProperty attribute for multiple reasons, e.g. [JsonProperty("kind")] and then Propercase the property. Commented Apr 1, 2014 at 12:21
  • I will try JsonProperty, but it worked yesterday by this way. Commented Apr 1, 2014 at 12:23
  • Indeed, that won't fix it, but I think it s a good practice... try completely clearing your browser cache... which browser are you using by the way? Commented Apr 1, 2014 at 12:24
  • Opera and Chrome and FireFox. Commented Apr 1, 2014 at 12:28

1 Answer 1

2

Can you try:

user =  new JavaScriptSerializer().Deserialize<A>( a );

since you say "a" has the value in the string. Maybe the problem is that you are calling ReadToEnd twice?

Sign up to request clarification or add additional context in comments.

3 Comments

I added picture after posted my question, therefore other users couldn't see it, Thank you very much, now it works. I added string a today )
For example I have name ="Jeyhun" surname="Elvin" in json file. I would like to get only name. Am I obliged to declare in my USERS class surname too? or it is enough USERS class { public string name {get; set;} }
I'd say try it out. I'm not sure. I would think it would work.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.