Click or drag to resize
Json.NET

Read Multiple Fragments With JsonReader

 

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

Sample
Types
public class Role
{
    public string Name { get; set; }
}
Usage
string json = @"{ 'name': 'Admin' }{ 'name': 'Publisher' }";

IList<Role> roles = new List<Role>();

JsonTextReader reader = new JsonTextReader(new StringReader(json));
reader.SupportMultipleContent = true;

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

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

    roles.Add(role);
}

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

// Admin
// Publisher