PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 20, 2022

[FIXED] How do I override a name in JSON returned by ASP.NET

 October 20, 2022     asp.net-web-api, datamember, json     No comments   

Issue

I have the following code in an ASP.NET Web API 2 app:

[DataMember(Name = "override")]
public bool? _override;

But the JSON I receive has that member named _override, not override. How can I change the naming in the JSON?


Solution

As asp.Net web API 2 uses Json.NET internally for json serialization/deserialization,

JsonProperty attribute can be used to override property name on serialization.

so [JsonProperty(PropertyName = "override")] should do the trick.

Thanks.



Answered By - shakib
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing