1

My JSON result is like this:

{
  "success": true,
  "result": {
      "name": "rocky",
      "age": 10,

  },
  "error": null,
  "unAuthorizedRequest": false
}

I want to delete ( "success": true,). I also want to change "result" to some other name.

How do I do this in ASP.NET MVC and JavaScript?

1
  • How have you received this json? Is it generated by your code or not? Where you want to change it, on client via js or on server-side via something else? What you mean by "in asp.net mvc and javascript"? First on works on the server, second one most likely on the client? For now it's too broad. Commented Aug 28, 2016 at 9:20

2 Answers 2

1

This JSON object should be a result of an JSON serialization that your application is made to one of your models (class) when it return a response.

Look for the model that is being serialized and modify it as you wish.

UPDATE:

in order to omit specific property in the serialization, use the JsonIgnore attribute, for example:

[JsonIgnore]
public bool Success{ get; set; }
Sign up to request clarification or add additional context in comments.

3 Comments

( "success": true) and "result" are added by default when I am doing Json("classname",JsonRequestBehavior.AllowGet). I think its nothing to do with normal class.
I neither have "success" or "result" in my class .Wrapper is added by default
to be more specific I m calling the controller from jquery ajax
0

You can write a model class for the response, and if you want to give other name to some of the properties like this

[DataMember(Name="othername")]
public string NameToChange { get; set; }

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.