© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
5 replies
FoxTrotCharlieZulu

❔ Assign JSON API Results To DTO

hey if I am returning json data from an API how do I assign the json data to my DTO? Meaning if I have a DTO that looks like this
public class TestDTO
{
   public Data data { get; set; }
}
public class Data
{
   public string fname { get; set; }
   public string lname { get; set; }
   public string phonenNumber { get; set; }
}
public class TestDTO
{
   public Data data { get; set; }
}
public class Data
{
   public string fname { get; set; }
   public string lname { get; set; }
   public string phonenNumber { get; set; }
}
but I only want to assign a value to
fname
fname
and
lname
lname
how would I set that up?

TestDTO td = null;

//code here

td = new TestDTO
{
    //how do I get to fname here?
};
TestDTO td = null;

//code here

td = new TestDTO
{
    //how do I get to fname here?
};
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Map json to a dto issue
C#CC# / help
2y ago
Minimal API : Model / DTO Help
C#CC# / help
2y ago
Model to DTO
C#CC# / help
3y ago
❔ Accessing json results for a weather api console app
C#CC# / help
3y ago