I\'m trying to deserialize a Facebook friend\'s Graph API call into a list of objects. The JSON object looks like:
{\"data\":[{\"id\":\"518523721\",\"name\"
If you're using .NET Core 3.0, you can use System.Text.Json (which is now built-in) to deserialize JSON.
The first step is to create classes to model the JSON. There are many tools which can help with this, and some of the answers here list them.
Some options are http://json2csharp.com, http://app.quicktype.io, or use Visual Studio (menu Edit → Paste Special → Paste JSON as classes).
public class Person
{
public string Id { get; set; }
public string Name { get; set; }
}
public class Response
{
public List Data { get; set; }
}
Then you can deserialize using:
var people = JsonSerializer.Deserialize(json);
If you need to add settings, such as camelCase
handling, then pass serializer settings into the deserializer like this:
var options = new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
var person = JsonSerializer.Deserialize(json, options);