Create a quick type for your json
public class RepoData
{
public string name { get; set; }
public string displayName { get; set; }
public string type { get; set; }
public bool enabled { get; set; }
public bool available { get; set; }
public string location { get; set; }
public string path { get; set; }
}
public class RootObject4
{
public List<RepoData> repoData { get; set; }
}
Here i create an console app for your demonstration purpose
class Program
{
static void Main(string[] args)
{
var json = @"{'repoData':[{'name':'Example','displayName':'Example1','type':'git','enabled':true,'available':true,'location':'Example.com','path':''}, {'name':'Example','displayName':'Example2','type':'git','enabled':true,'available':true,'location':'Example.com','path':''}]}";
RootObject4 rootObject4 = JsonConvert.DeserializeObject<RootObject4>(json);
List<string> displayNames = new List<string>();
foreach (var item in rootObject4.repoData)
{
displayNames.Add(item.displayName);
}
displayNames.ForEach(x => Console.WriteLine(x));
Console.ReadLine();
}
}
Alternative: If you don't want to create any classes then JObject
will better handle your json and you will extract displayName
values by below code sample console app.
class Program
{
static void Main(string[] args)
{
var json = @"{'repoData':[{'name':'Example','displayName':'Example1','type':'git','enabled':true,'available':true,'location':'Example.com','path':''}, {'name':'Example','displayName':'Example2','type':'git','enabled':true,'available':true,'location':'Example.com','path':''}]}";
JObject jObject = JObject.Parse(json);
var repoData = jObject["repoData"];
var displayNames = repoData.Select(x => x["displayName"]).Values().ToList();
displayNames.ForEach(x => Console.WriteLine(x));
Console.ReadLine();
}
}
Output:
