Click here to Skip to main content
15,878,602 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have model
public class AppDto
    {
         public int Roll_Number { get; set; }
         public string App_name { get; set; }
    }


i want to return Json result like (change the property name in json result.)

[{
   RollNumber:1,
   AppName: "MyApp" 
}]


What I have tried:

public class AppDto
    {
         [JsonProperty(PropertyName = "RollNumber")]
         public int Roll_Number { get; set; }
         [DataMember(Name = "AppName")]
         public string App_name { get; set; }
    }
Posted
Updated 9-Nov-21 4:58am
v2
Comments
Richard MacCutchan 9-Nov-21 11:14am    
And? Do you have a question?
Siddharth Rai 9-Nov-21 11:47am    
I have added the attribute on model property and calling the api form Swagger but result showing in swagger is same as
[{
Roll_Number:1,
App_Name: "MyApp"
}]

but my requirement is
[{
RollNumber:1,
AppName: "MyApp"
}]
Richard MacCutchan 9-Nov-21 12:00pm    
Sorry, I know nothing about Swagger.
Siddharth Rai 9-Nov-21 13:02pm    
thanks for your time sir, I think i am not able to explain my requirement .
let me try one more last time.

i am using api which return json result. [{
Roll_Number:1,
App_Name: "MyApp"
}]
where key name same as Model property name. But i my requirement is that can get the result like .
[{
RollNumber:1,
AppName: "MyApp"
}]
without changing the model property name. as api result.(key name is different then model property name.)
Richard MacCutchan 9-Nov-21 13:55pm    
You can only receive what the sender sends to you. You can change the names of classes in your program, but the original JSON text is as sent.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900