Skip to content

Latest commit

 

History

History
50 lines (40 loc) · 1.49 KB

ReadMultipleContentWithJsonReader.md

File metadata and controls

50 lines (40 loc) · 1.49 KB

Read Multiple Fragments With JsonReader

This sample sets Argon.JsonReader.SupportMultipleContent to true so that multiple JSON fragments can be read from a System.IO.Stream or System.IO.TextReader.

public class Role
{
    public string Name { get; set; }
}

snippet source | anchor

var json = "{ 'name': 'Admin' }{ 'name': 'Publisher' }";

var roles = new List<Role>();

var reader = new JsonTextReader(new StringReader(json))
{
    SupportMultipleContent = true
};

while (true)
{
    if (!reader.Read())
    {
        break;
    }

    var serializer = new JsonSerializer();
    var role = serializer.Deserialize<Role>(reader);

    roles.Add(role);
}

foreach (var role in roles)
{
    Console.WriteLine(role.Name);
}

// Admin
// Publisher

snippet source | anchor