I would like to get data out of AF Table as a JObject and deserialized into something generic and useful using PI Web API and C#.NET. For example, I have a static AF table named Products composed of 5 columns: Description, SortOrder, Group, GravityMinimum, GravityMaximum. I can easily get the base table information as follows:
string uri = string.Format(@"https://localhost/piwebapi/tables?path=\\(my dev server)\(my dev AF database)\Tables[Products]");
JObject jsonObject = this.GetSync(uri);
Note that "this" is a PI Web API wrapper class I wrote that extends the HttpClient class. The meat of the GetSync method deserializes the HttpClient.GetAsync(uri) as a JObject and returns the JObject.
I can then get the Data uri from the "Links" section and pass that uri to the same GetSync method to get another JObject that represents the data of the table. Looking at the documentation for the GetData action, it looks like the "Rows" section contains the data I want. What is the best way to get that data into a .NET object? I've tried doing the following, which works, but this means I have to hard code column names in my generic PI Web API wrapper instead of being able to create a generic "table" of data, then pass it back to the caller to parse into the desired data model.
for (int i = 0; i < jsonObject["Rows"].Count(); i++)
string desc = jsonObject["Rows"][i]["Description"].ToString();
string sort = jsonObject["Rows"][i]["SortOrder"].ToString();
string group = jsonObject["Rows"][i]["Group"].ToString();
string gmin = jsonObject["Rows"][i]["GravityMinimum"].ToString();
string gmax = jsonObject["Rows"][i]["GravityMaximum"].ToString();
//add new Product to some List<Product> with these arguments
Thanks in advance!