question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Json Data in response is coming Null

See original GitHub issue

Hi, Am fairly new to Restsharp. Currently using RestSharp in my MVC 5 project and doing the below and even though I have data, am seeing null in response.Data. Can you please let me know if am doing anything wrong?

 private RestClient client;
        private string url = "http://localhost:58482/api/tblObjectPermission/GetAlltblObjectPermission"; 
        public TblObjectPermissionClient()
        {
            client = new RestClient(url);
        }
        public IEnumerable<tblObjectPermission> GetAlltblObjectPermission()
        {
            var request = new RestRequest("api/serverdata", Method.GET);
            request.RequestFormat = DataFormat.Json;

        var response = client.Execute<List<tblObjectPermission>>(request);

        if (response.Data == null)
            throw new Exception(response.ErrorMessage);
        return response.Data;
    }

Model class is

 public partial class tblObjectPermission
    {
        public int ObjectPermissionID { get; set; }
        public bool DeleteYN { get; set; }
        public Nullable<int> ObjectID { get; set; }
        public Nullable<int> SubscriberID { get; set; }
        public Nullable<int> UserID { get; set; }
        public Nullable<int> ObjectAccessID { get; set; }
        public Nullable<System.DateTime> ChangeDate { get; set; }
        public Nullable<int> ChangeUser { get; set; }
        public byte[] RowVersion { get; set; }
        public virtual tblObject tblObject { get; set; }
        public virtual tsysObjectAccess tsysObjectAccess { get; set; }
    }

Appreciate your help.

Thanks Roopesh

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
spurdatacommented, Nov 15, 2016

See http://stackoverflow.com/questions/10324526/restsharp-not-deserializing-json-object-list-always-null

After you declare your request, try adding a line to explicitly specify the content type as JSON:

var request = new RestRequest(Method.GET);
request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };

Worked for me.

2reactions
alexeyzimarevcommented, Jan 31, 2018

SimpleJson serialization will not be amended because it is not our code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Representing null in JSON
If you want to represent a null value in JSON, the entire JSON string (excluding the quotes containing the JSON string) is simply...
Read more >
Handling JSON null and empty arrays and objects
Null values. JSON has a special value called null which can be set on any type of data including arrays, objects, number and...
Read more >
How to handle null keys in JSON response?
I am doing JSON.deserialize(response.getBody(), Person.class), if you meant by consume. – nSv23. Jan 5, 2021 at 17:02.
Read more >
JSON returning Null - Microsoft Q&A
If the data is returned correctly from the API but the schema is incorrect then the parsing will not happen correctly and the...
Read more >
Solved: Json object giving null value after sending json a...
Solved: Hi All, I have created Sling Servlet and I wanted to pass json raw data to the Slingservlet but it is showing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found