locked
JsonConvert.DeserializeObject is not properly working

    Question

  • Hi.

    i have a api link which return the json like this:

    {"login_type":"Enterprise","user_id":"2"} (For Simplicity)

    i have generate the JSON to C# class through special paste feature in VS2013

    which is like this:

    public class Rootobject
    {
    public string login_type { get; set; }
    public string user_id { get; set; }
    }

    Then i create a class which sets or gets the objects in Rootobject class

    public class Class

    {

    public Rootobject[] Rootobject{ get; set; }

    }

    Then on my Button Function i write:

             

     var Json = new HttpClient();
                string uri = "Example";
               string response = await  Json.GetStringAsync(new Uri(uri));
             Class1 rootObject =  JsonConvert.DeserializeObject<Class1>(response);
           

    But it give rootObject to NULL.
    Thanks in Advance :)


    MobinYaqoob

    Wednesday, July 2, 2014 9:15 PM

All replies

  • No comment can be passed unless the actual (without simplicity) JSON string is shared. Most optimally you'll have to tweak the JSON a bit (appending { or giving the array a name) prior deserializing. Please share the actual JSON

    Wednesday, July 2, 2014 9:24 PM
  • In JSON {"firstName":"John", "lastName":"Doe"}  it denotes an object .

    Due to my JSON Lenght i am not figured that its a single object and Use array.
    then i simply use RootObject and it works :)


    MobinYaqoob

    Wednesday, July 2, 2014 9:40 PM