Json Data in response is coming Null
See original GitHub issueHi, 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:
- Created 7 years ago
- Comments:10 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:
Worked for me.
SimpleJson serialization will not be amended because it is not our code.