Model class:
public class User
{
public string NS_ID { get; set; }
public string TONV_ABC { get; set; }
public string NAME_ABC { get; set; }
public string MAABC { get; set; }
}
Result json when testing in Postman:
"nS_ID": "",
"tonV_ABC": "",
"namE_ABC": "",
"maabc": "F02",
This is the result I want:
"NS_ID": "",
"TONV_ABC": "",
"NAME_ABC": "",
"MAABC": "F02",
This is my API:
[HttpGet]
[Route("test")]
public ActionResult test()
{
User u = new User();
u.NS_ID = "";
u.TONV_ABC = "";
u.NAME_ABC = "";
u.MAABC = "F02";
return Ok(u);
}
Please help me
I try convert but it’s not working
2
Answers
You can try to deserialize the JSON string to a
Dictionary<string, object>
. then create another Dictionary. iterate over the first dictionary and add all the key-value pairs to the new dictionary why making the key to upper case using theToUpper()
method. then serialize the new dictionary to the JSON string.Sample code:
Note: I have used NewtonSoft.json. you can get it from the Nuget package manager.
.net 7: You just need to add the following configuration to
Program.cs
:.net core 3.1:
add the following configuration to
startup.cs
🙁ConfigureServices(IServiceCollection services)
)