Hi All,
I am attempting to query a REST API and I am able to successfully return the information to a string. I am trying to parse this string correctly into something that is more useful or visually appealing.
I am not sure how to tackle this. Here is the working code.
namespace WFApi
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void dellSearchCmd_Click(object sender, EventArgs e)
{
try
{
queryFetch("https://sandbox.api.del.com/support/assetinfo/v4/getassetwarranty/" + serviceTagInput.Text + "?apikey=123456");
}
catch (WebException webex)
{
MessageBox.Show("Error Detected:", webex.Message);
}
}
private void queryFetch(string uri)
{
var wRequest = (HttpWebRequest)WebRequest.Create(uri);
var wResponse = (HttpWebResponse)wRequest.GetResponse();
var reader = new StreamReader(wResponse.GetResponseStream());
string s = reader.ReadToEnd();
textBox1.Text = s;
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Now I can return String S into a textbox and the data looks like the following.
{"AssetWarrantyResponse":[{"AssetHeaderData":{"BUID":"11","ServiceTag":"JXYAHD","ShipDate":"2014-12-30T00:00:00","CountryLookupCode":"US","LocalChannel":"14","CustomerNumber":"1003","ItemClassCode":"5U004","IsDuplicate":false,"MachineDescription":"Latitude E7440","OrderNumber":"748942881","ParentServiceTag":null},"ProductHeaderData":{"SystemDescription":"Latitude E7440","ProductId":"latitude-e7440-ultrabook","ProductFamily":"Laptops","LOB":"Latitude","LOBFriendlyName":"Latitude"},"AssetEntitlementData":[{"StartDate":"2015-12-31T00:00:00","EndDate":"2017-12-30T23:59:59","ServiceLevelDescription":"Next Business Day Onsite","ServiceLevelCode":"ND","ServiceLevelGroup":5,"EntitlementType":"EXTENDED","ServiceProvider":"UNY","ItemNumber":"995-8084"},{"StartDate":"2015-12-31T00:00:00","EndDate":"2017-12-30T23:59:59","ServiceLevelDescription":"ProSupport","ServiceLevelCode":"TS","ServiceLevelGroup":8,"EntitlementType":"EXTENDED","ServiceProvider":"DELL","ItemNumber":"995-8774"},{"StartDate":"2014-12-30T00:00:00","EndDate":"2015-12-30T23:59:59","ServiceLevelDescription":"Next Business Day Onsite","ServiceLevelCode":"ND","ServiceLevelGroup":5,"EntitlementType":"INITIAL","ServiceProvider":"UNY","ItemNumber":"995-8054"},{"StartDate":"2014-12-30T00:00:00","EndDate":"2015-12-30T23:59:59","ServiceLevelDescription":"ProSupport","ServiceLevelCode":"TS","ServiceLevelGroup":8,"EntitlementType":"INITIAL","ServiceProvider":"DELL","ItemNumber":"995-8754"},{"StartDate":"2014-12-30T00:00:00","EndDate":"2023-01-02T23:59:59","ServiceLevelDescription":"Dell Digitial Delivery","ServiceLevelCode":"D","ServiceLevelGroup":11,"EntitlementType":"INITIAL","ServiceProvider":"DELL","ItemNumber":"422-0007"},{"StartDate":"2014-12-30T00:00:00","EndDate":"2023-01-02T23:59:59","ServiceLevelDescription":"Dell Digitial Delivery","ServiceLevelCode":"D","ServiceLevelGroup":11,"EntitlementType":"INITIAL","ServiceProvider":"DELL","ItemNumber":"421-9982"}]}],"InvalidFormatAssets":{"BadAssets":[]},"InvalidBILAssets":{"BadAssets":[]},"ExcessTags":{"BadAssets":[]},"AdditionalInformation":null}
Is there an easy way to place this into a datagrid or make this string easier to work with? For instance returning just the Shipdate or ServiceTag to the textbox?
Id personally like to make this dump into a datagrid so it can all be viewed.
Any recommendations or assistance would be greatly appreciated.
I've tried NewtonSoft and JavaSerializer to do so but have had no luck.