I have a class with 2 properties, but I'm getting a JSON object with a few properties that I don't need. I want to use JsonConvert.DeserializeObject but I'm getting an error because my class doesn't correspond to the JSON object. Do you have any code example on how to solve this using JsonConvert? I want to avoid using JObject.Parse
How I tried to use JsonConvert:
var data = JsonConvert.DeserializeObject<LinkedInUser>(await GetData(token));
GetData returns the JSON object
LinkedInUseris the class that contains the properties that exist in the JSON object that i need
edit: I'm trying to get data from linkedin
This is the Json object:
{
"id":"REDACTED",
"firstName":{
"localized":{
"en_US":"Tina"
},
"preferredLocale":{
"country":"US",
"language":"en"
}
},
"lastName":{
"localized":{
"en_US":"Belcher"
},
"preferredLocale":{
"country":"US",
"language":"en"
}
},
"profilePicture": {
"displayImage": "urn:li:digitalmediaAsset:B54328XZFfe2134zTyq"
}
}
And this is LinkedInUser object:
namespace project.DTOs.Models
{
public class LinkedInUser
{
public string FirstName { get; set;}
public string LastName { get; set; }
}
}
I can't convert the JSON to LinkedInUser using JsonConvert.DeserializeObject this way, does anyone know a way to do it easily?