user5419119
user5419119

Reputation: 223

ASP.NET MVC rename JSON object wrapper

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?

Upvotes: 1

Views: 223

Answers (2)

Yair Nevet
Yair Nevet

Reputation: 13003

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; }

Upvotes: 1

Burak Karakuş
Burak Karakuş

Reputation: 1410

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; }

Upvotes: 0

Related Questions