0

I am getting bellow result when serializing the C# Model into JSON object.

This is my model.

public class ResultSet 
{
public int RowsInserted { get; set; }
public string RequestStatus { get; set; }
}

In my controller, I am creating an object to the model and assigning the values.

{
     ResultSet objResultSet = new ResultSet(); 
     objResultSet.RowsInserted = result;
     objResultSet.RequestStatus = "SuccessFul";
}

When returning the result I used the JsonConvert.Serialize

  return JsonConvert.SerializeObject(objResultSet);

I am getting the JSON result like the bellow :

"{\"RowsInserted\":1,\"RequestStatus\":\"SuccessFul\"}"

The actual result I am expecting is:

{"RowsInserted":1,"RequestStatus":"SuccessFul"}

3
  • Where are you checking output? in C# string having "(quotes) are escaped with \ Commented Sep 19, 2018 at 9:40
  • This is my web-service, I saw the results from REST tool. Commented Sep 19, 2018 at 11:35
  • Try answers to this stackoverflow.com/questions/18225921/… Commented Sep 19, 2018 at 11:41

1 Answer 1

0

I resolved this by changing the return type of method to the class instead of a string like this.

New method:

public ResultSet getData()
{
     ResultSet objResultSet = new ResultSet(); 

     objResultSet.RowsInserted = result;
     objResultSet.RequestStatus = "SuccessFul";

     return objResultSet;
}

Old Method

public string getData()
{
     ResultSet objResultSet = new ResultSet(); 

     objResultSet.RowsInserted = result;
     objResultSet.RequestStatus = "SuccessFul";

     return JsonConvert.SerializeObject(objResultSet);
}
Sign up to request clarification or add additional context in comments.

Comments

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.