08-07-21 08:59 AM
11-07-21 07:05 PM
12-07-21 08:15 AM
JObject o = JObject.Parse(Response_Content);
JToken i = o.SelectToken("$..issues
.key");
12-07-21 02:14 PM
JArray topArray = JArray.Parse(json);
JArray issues = (JArray)array.SelectToken(query);
foreach (JObject issue in issues)
{
string id = (string)issue["id"];
string expand = (string)issue["expand"];
string self = (string)issue["self"];
string key = (string)issue["key"];
// Do something with the values (ex. populate a DataTable and return to process as Collection.
}
Keep in mind, this is loading an array at the beginning. If you full JSON is actually an object you'd need to do a JObject.Parse() to load it and then use SelectToken() to pull out the issues array.
Cheers,
12-07-21 02:17 PM
Hi Mateusz,
From your Json path I assume each object inside issues array has key which you are trying to retrieve, right? you can try out following where inside foreach you can write what you want to do or just put it in Datatable to return a collection.
IEnumerable<JToken> i = o.SelectTokens("$..issues
.key");
foreach(JToken j in i)
{
Console.WriteLine(j.ToString());
}
13-07-21 02:44 PM
JObject o = JObject.Parse(Response_Content);
JToken issues = o.SelectToken("$..issues
.key");
var dataTable = new DataTable();
dataTable.Columns.Add("id");
dataTable.Columns.Add("expand");
dataTable.Columns.Add("self");
dataTable.Columns.Add("key");
foreach (JObject issue in issues)
{
DataRow row = dataTable.NewRow();
row["id"] = (string)issue["id"];
row["expand"] = (string)issue["expand"];
row["self"] = (string)issue["self"];
row["key"] = (string)issue["key"];
dataTable.Rows.Add(row);
}
Issues = dataTable;
13-07-21 03:05 PM
13-07-21 03:06 PM
JObject o = JObject.Parse(Response_Content);
IEnumerable<JToken> i = o.SelectTokens("$..issues
.key");
var tempIssue = "";
foreach(JToken j in i)
{
tempIssue = tempIssue +","+(j.ToString());
}
Issues = tempIssue;
For the testing purposes I was able to return it to a string with separator 🙂
Thanks!!!
13-07-21 03:08 PM