1

NET MVC Web API's, i created a class of Response so that All Routes return same response pattern,

[DataContract]
    public class Response
    {
        [DataMember]
        public string ResponseMessage { get; set; }
        [DataMember]
        public int ResponseCode { get; set; }
        [DataMember]
        public object ResponsePayload { get; set; }        
    }

I am calling APIResponse Method from All routes to return Response, Every time i would Pass Either DataTable or DataSet in object responseObj param of below function, I have to use ADO.NET DB Access layer, :)

private Object APIResponse(object responseObj, string _message = Constants.RESPONSE_MESSAGE_SUCCESS, int code = _RESPONSE_SUCCESS_CODE)
        {

            Response _response = new Response();
            _response.ResponsePayload = responseObj;
            _response.ResponseMessage = _message;
           _response.ResponseCode = code;

            return Newtonsoft.Json.JsonConvert.SerializeObject(_response);
        }

if my responseObj param is of type DataSet, than i get Unwanted Quotes and Backslashes (Like in PHP if Magic Quotes are enable on Server) which produce a invalid JSON, Can you please help me in fixing this issue, to remove these slashes,

Sample JSON:

"{\"ResponseMessage\":\"Success\",\"ResponseCode\":200,\"ResponsePayload\":{\"StatusList\":[{\"StatusId\":1,\"Status\":\"To Be Dispatched\", ...........
5
  • In case of DataTable it create correct Json, only creating invalid Json in Case of DataSet, Commented Oct 10, 2013 at 21:39
  • Is that definitely the returned JSON and not just a Visual Studio debugger "quickview" representation of it? (Which will add the backslashes.) Commented Oct 10, 2013 at 23:38
  • This is JSON response that i can see in browser, Commented Oct 11, 2013 at 5:46
  • Why are you reinventing HTTP on top of HTTP? HTTP already has HttpStatusCode and ReasonPhrase for this purpose. Commented Oct 11, 2013 at 11:18
  • @DarrelMiller , i tried HttpResponse but that did not works for me, i needed Json for My DataTable/DataSet, Can you help me? Commented Oct 11, 2013 at 15:23

1 Answer 1

1

you should define your Get like this

public IEnumerable<string> Get(int id1)

public List<Response> Get( int id1)

instead of this

public string Get(int id1)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.