Reputation: 195
What I'm trying to do is string specific value from JSON.
JSON link
How would i be able to string Specific data from it to a textbox ? I.E string Value for "Asset Tag" & "Warranty"
I already have the code to DeserializeObject and make it show in a text box. I'm just not sure how to pick specific data off it since i don't need most of the rubbish.
string Serial = "G88NJX1";
WebClient webClient = new WebClient();
dynamic result = JsonConvert.DeserializeObject(webClient.DownloadString("https://api.dell.com/support/v2/assetinfo/warranty/tags.json?svctags=" + Serial + "&apikey=1adecee8a60444738f280aad1cd87d0e"));
textBox1.Text = Convert.ToString(result);
Upvotes: 1
Views: 972
Reputation: 4464
I see that you are using the Dell warranty API. Instead of decoding their JSON string, create a service reference in your project to them. Put their API in your service reference URL. Back when I wrote this all I had was the IP address and not the DNS name, so my service reference to the Dell API is:
http://143.166.84.118/services/assetservice.asmx?WSDL
Here is how I get the warranty data (and other stuff). It uses the API's EntitlementData object to store info.
string ServiceTag = "your service tag here";
DellServiceReference.AssetServiceSoapClient svc = new DellServiceReference.AssetServiceSoapClient();
Guid DellFeeder = new Guid("12345678-1234-1234-1234-123456789012");
DellServiceReference.Asset[] assets = svc.GetAssetInformation(DellFeeder, "dellwarrantycheck", ServiceTag);
// go through each warranty
DellServiceReference.EntitlementData[] entitlements = assets[0].Entitlements;
foreach (DellServiceReference.EntitlementData warr in entitlements)
{
DateTime start = warr.StartDate;
DateTime stop = warr.EndDate;
// do stuff with this
}
Upvotes: 1
Reputation: 4883
You can try with this:
JArray obj = (JArray)JsonConvert.DeserializeObject(yourJSONString);
object a = obj[0]["theKeyYouNeed"];
Then you convert to the type you need.
Hope that helps
Upvotes: 1