Related
I am getting the following response from an API
"results": {
"wan1": {
"id": "wan1",
"name": "wan1",
"alias": "",
"mac": "00:00:00:00:00:00",
"ip": "102.165.223.199",
"mask": 24,
"link": true,
"speed": 1000.0,
"duplex": 1,
"tx_packets": 501850173,
"rx_packets": 307154377,
"tx_bytes": 442319826490,
"rx_bytes": 234140958061,
"tx_errors": 0,
"rx_errors": 0
},
"dmz": {
"id": "dmz",
"name": "dmz",
"alias": "",
"mac": "00:00:00:00:00:00",
"ip": "10.10.10.1",
"mask": 24,
"link": false,
"speed": 0.0,
"duplex": 0,
"tx_packets": 0,
"rx_packets": 0,
"tx_bytes": 0,
"rx_bytes": 0,
"tx_errors": 0,
"rx_errors": 0
},
"internal1": {
"id": "internal1",
"name": "internal1",
"alias": "",
"mac": "00:00:00:00:00:00",
"ip": "0.0.0.0",
"mask": 0,
"link": false,
"speed": 0.0,
"duplex": 0,
"tx_packets": 0,
"rx_packets": 0,
"tx_bytes": 0,
"rx_bytes": 0,
"tx_errors": 0,
"rx_errors": 0
}
},
"vdom": "root",
}
I have tried a few approaches to representing this JSON in c# objects
{
public Dictionary<string, List<Result>> Result { get; set; }
}
public class Result
{
public string name { get; set; }
public string ip { get; set; }
public int tx_bytes { get; set; }
public int rx_bytes { get; set; }
}
And here is the method I am using to deserialize the JSON:
var result = await client.Request()
.AppendPathSegment("api/v2/monitor/system/interface")
.SetQueryParam("access_token", token)
.GetJsonAsync<InterfaceResponse>(cancellationToken: cancellationToken);
It should be simple, but for some reason, I can't figure out the correct object representation, but when I debug I am getting null
Thanks for the help.
I can see 2 issues:
It's "results" not "result".
"results" looks like Dictionary<string, Result> not Dictionary<string, List<Result>>.
Additionally, if you're using System.Text.Json then casing may matter depending on your settings.
try this
var jsonParsed = JObject.Parse(json);
Dictionary<string,Result> results = jsonParsed["results"]
.ToObject<Dictionary<string,Result>>();
string vdom = (string)jsonParsed["vdom"];
public class Result
{
public string name { get; set; }
public string ip { get; set; }
public long tx_bytes { get; set; }
public long rx_bytes { get; set; }
//another properties
}
You need to fix the classes:
public class InterfaceResponse
{
// 1. rename or use attributes
// 2. fix type from Dictionary<string, List<Result>>
public Dictionary<string, Result> results { get; set; }
}
public class Result
{
public string name { get; set; }
public string ip { get; set; }
public long tx_bytes { get; set; } // use long, some of the values are too big to fit int
public long rx_bytes { get; set; } // use long, some of the values are too big to fit int
}
I am trying to deserialize a json response I get from a web call. I have it 90 percent figured out. The only part I am having a hard time figuring out is there are these json arrays which have data in them and each array name is unique using the email address. I have not been able to figure out how to turn the Email Arrays into 1. Dynamic and having it create many lists or just a couple depending on what comes back in the response and also dynamically naming the list arrays to put the data into the Records class.
As you can see in the Records class I need this to be more dynamic and flexible to receive any and all emails.
Below is the json:
{
"result": {
"records": {
"joeblow#gmail.com": [
{
"OrderId": "d9535109-d305-4584-a503-8194bbcfcff2",
"CompletedOrderId": "BCFCFF2",
"CustomerId": 1212,
"CompletedTime": "2020-10-26 13:32:02",
"Email": "joeblow#gmail.com",
"ShippingFirstName": "Joe",
"ShippingMiddleName": "",
"ShippingLastName": "Blow",
"LineItems": {
"tfl.es.bluray": { "qty": 1 },
"booklets.en.ebook": { "qty": 1 }
}
}
],
"cleob#hotmail.com": [
{
"OrderId": "7bf97b3a-bc46-411c-bc30-12563326dba0",
"CompletedOrderId": "326DBA0",
"CustomerId": 1212,
"CompletedTime": "2020-10-26 20:07:44",
"Email": "cleob#hotmail.com",
"ShippingFirstName": "Cleo",
"ShippingMiddleName": "",
"ShippingLastName": "Blue",
"LineItems": {
"tfl.es.bluray": { "qty": 1 },
"booklets.en.ebook": { "qty": 1 },
"aos.en.pb": { "qty": 1 },
"course-tos.en.olr": { "qty": 1 },
"pow-hsk-nofilm.en.combo": { "qty": 1 },
"course-organizing.en.olr": { "qty": 1 }
}
}
],
"johnd#gmail.com": [
{
"OrderId": "630f0dda-94c3-4b82-a070-2554004dce29",
"CompletedOrderId": "04DCE29",
"CustomerId": 12345,
"CompletedTime": "2020-10-25 21:52:04",
"Email": "johnd#gmail.com",
"ShippingFirstName": "John",
"ShippingMiddleName": "",
"ShippingLastName": "Doe",
"LineItems": {
"tfl.es.bluray": { "qty": 1 },
"booklets.en.ebook": { "qty": 1 },
"aos.en.pb": { "qty": 1 },
"course-tos.en.olr": { "qty": 1 },
"pow-hsk-nofilm.en.combo": { "qty": 1 },
"course-organizing.en.olr": { "qty": 1 },
"oak-2007.en.cd": { "qty": 1 }
}
}
]
},
"errors": [
{
"id": "bademailaddress-yahoo.com",
"message": "Email address 'bademailaddress-yahoo.com' is not a valid email address"
}
]
},
"jsonrpc": "2.0",
"id": 12345634523
}
And the classes I made for the json deserialization:
public partial class JsonEmailDeSerializer
{
[JsonProperty("result")]
public Result Result { get; set; }
[JsonProperty("jsonrpc")]
public string Jsonrpc { get; set; }
[JsonProperty("id")]
public long Id { get; set; }
}
public partial class Result
{
[JsonProperty("records")]
public Records Records { get; set; }
[JsonProperty("errors")]
public List<Error> Errors { get; set; }
}
public partial class Error
{
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("message")]
public string Message { get; set; }
}
public partial class Records
{
[JsonProperty("joeblow#gmail.com")]
public List<MailCom> JoeblowGmailCom { get; set; }
[JsonProperty("cleob#hotmail.com")]
public List<MailCom> CleobHotmailCom { get; set; }
[JsonProperty("johnd#gmail.com")]
public List<MailCom> JohndGmailCom { get; set; }
}
public partial class MailCom
{
[JsonProperty("OrderId")]
public Guid OrderId { get; set; }
[JsonProperty("CompletedOrderId")]
public string CompletedOrderId { get; set; }
[JsonProperty("CustomerId")]
public long CustomerId { get; set; }
[JsonProperty("CompletedTime")]
public DateTimeOffset CompletedTime { get; set; }
[JsonProperty("Email")]
public string Email { get; set; }
[JsonProperty("ShippingFirstName")]
public string ShippingFirstName { get; set; }
[JsonProperty("ShippingMiddleName")]
public string ShippingMiddleName { get; set; }
[JsonProperty("ShippingLastName")]
public string ShippingLastName { get; set; }
[JsonProperty("LineItems")]
public Dictionary<string, LineItem> LineItems { get; set; }
}
public partial class LineItem
{
[JsonProperty("qty")]
public long Qty { get; set; }
}
public partial class JsonEmailDeSerializer
{
public static JsonEmailDeSerializer FromJson(string json) => JsonConvert.DeserializeObject<JsonEmailDeSerializer>(json, FedExShipper.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this JsonEmailDeSerializer self) => JsonConvert.SerializeObject(self, FedExShipper.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
Common approach to deserializing json with dynamic property names is to use Dictionary<string, ...>, in this case - Dictionary<string, List<MailCom>> can be used for Records property:
public partial class Result
{
[JsonProperty("records")]
public Dictionary<string, List<MailCom>> Records { get; set; }
[JsonProperty("errors")]
public List<Error> Errors { get; set; }
}
Json.NET can treat json object properties as keys for dictionary which makes it suitable to deserialize such dynamic data. The same is true for System.Text.Json.
That will never serialize to a class properly.
You'll have to use a lower-level API like Utf8JsonReader to read that level in the document, at least.
How can I turn the string fetched from the URL to a usable object? I've seen several Newtonsoft.Json examples, but none of them work with the layout of the object in the URL.
The code below is what I have so far. (the DeserializeObject part currently in the code doesn't work) due to the layout of the object.
JSON Data:
{
"totals": {
"confirmed": 4011,
"dead": 23,
"recovered": 7,
"changes": {
"newToday": 239,
"newYesterday": 378,
"diff": -139,
"deathsToday": 4,
"deathsYesterday": 5
}
},
"cases": [
{
"confirmed": 989,
"dead": 4,
"recovered": 1,
"name": "Oslo",
"countyCode": "03",
"confirmedPer1kCapita": 1.426111833700075
},
{
"confirmed": 1138,
"dead": 7,
"recovered": 1,
"name": "Viken",
"countyCode": "30",
"confirmedPer1kCapita": 0.9168805114549636
},
{
"confirmed": 284,
"dead": 2,
"recovered": 1,
"name": "Innlandet",
"countyCode": "34",
"confirmedPer1kCapita": 0.7647050904048359
},
{
"confirmed": 440,
"dead": 0,
"recovered": 3,
"name": "Vestland",
"countyCode": "46",
"confirmedPer1kCapita": 0.6912467735271338
},
{
"confirmed": 304,
"dead": 0,
"recovered": 0,
"name": "Rogaland",
"countyCode": "11",
"confirmedPer1kCapita": 0.633475865403049
},
{
"confirmed": 285,
"dead": 0,
"recovered": 0,
"name": "Trøndelag",
"countyCode": "50",
"confirmedPer1kCapita": 0.608062265575995
},
{
"confirmed": 130,
"dead": 2,
"recovered": 0,
"name": "Troms og Finnmark",
"countyCode": "54",
"confirmedPer1kCapita": 0.5342956134330138
},
{
"confirmed": 159,
"dead": 1,
"recovered": 0,
"name": "Agder",
"countyCode": "42",
"confirmedPer1kCapita": 0.5175259007066344
},
{
"confirmed": 149,
"dead": 1,
"recovered": 0,
"name": "Vestfold og Telemark",
"countyCode": "38",
"confirmedPer1kCapita": 0.3552728209138857
},
{
"confirmed": 91,
"dead": 0,
"recovered": 1,
"name": "Møre og Romsdal",
"countyCode": "15",
"confirmedPer1kCapita": 0.34308809446610217
},
{
"confirmed": 42,
"dead": 0,
"recovered": 0,
"name": "Nordland",
"countyCode": "18",
"confirmedPer1kCapita": 0.17410408937343255
}
],
"updated": {
"ts": "2020-03-28T21:23:18+01:00",
"by": "Morten Asbjørnsen",
"version": "5154"
}
}
Code:
public class Program
{
public static void Main(string[] args)
{
string Address = "https://redutv-api.vg.no/corona/v1/sheets/norway-table-overview?region=county";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Address);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = null;
if (String.IsNullOrWhiteSpace(response.CharacterSet))
readStream = new StreamReader(receiveStream);
else
readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
string data = readStream.ReadToEnd();
response.Close();
readStream.Close();
Console.WriteLine(data);
//No clue...
Statistic statistic = JsonConvert.DeserializeObject<Statistic>(data);
}
}
public class Statistic
{
//needs modifying.
public string confirmed.total {get;set;}
}
}
Your c# class has to have structure similar to json
(Note: I'm specifically skipping some details of deserialization for simplicity, but in short the parts of your C# class that don't match your json will be skipped - you will have default values)
Here's what you can do
Download your json from https://redutv-api.vg.no/corona/v1/sheets/norway-table-overview?region=county
Generate a c# class based on that json using some tool, for example http://json2csharp.com/ or https://www.jsonutils.com/
Rename the generated RootObject into something meaningful - this is your Statistics class
Depending on the tooling you will get a slightly different result, something similar to the code below
(Note: Some details may differ, like collection types can use array, List<T> or IList<T> depending on the tooling)
As a bonus, if you're able to use .NET Core 3x, Try the new System.Text.Json APIs - this is the recommended approach going forward, not Newtonsoft.JSON
public class Changes
{
public int newToday { get; set; }
public int newYesterday { get; set; }
public int diff { get; set; }
public int deathsToday { get; set; }
public int deathsYesterday { get; set; }
}
public class Totals
{
public int confirmed { get; set; }
public int dead { get; set; }
public int recovered { get; set; }
public Changes changes { get; set; }
}
public class Case
{
public int confirmed { get; set; }
public int dead { get; set; }
public int recovered { get; set; }
public string name { get; set; }
public string countyCode { get; set; }
public double confirmedPer1kCapita { get; set; }
}
public class Updated
{
public DateTime ts { get; set; }
public string by { get; set; }
public string version { get; set; }
}
public class RootObject
{
public Totals totals { get; set; }
public List<Case> cases { get; set; }
public Updated updated { get; set; }
}
You need an object structure in C# which matches the structure of the JSON you're downloading.
Sites like json2csharp will auto-generate a structure for you and will work with most JSON you can think of.
For the data presented by that URL when I visited it just now, it suggests this:
public class Changes
{
public int newToday { get; set; }
public int newYesterday { get; set; }
public int diff { get; set; }
public int deathsToday { get; set; }
public int deathsYesterday { get; set; }
}
public class Totals
{
public int confirmed { get; set; }
public int dead { get; set; }
public int recovered { get; set; }
public Changes changes { get; set; }
}
public class Case
{
public int confirmed { get; set; }
public int dead { get; set; }
public int recovered { get; set; }
public string name { get; set; }
public string countyCode { get; set; }
public double confirmedPer1kCapita { get; set; }
}
public class Updated
{
public DateTime ts { get; set; }
public string by { get; set; }
public string version { get; set; }
}
public class RootObject
{
public Totals totals { get; set; }
public List<Case> cases { get; set; }
public Updated updated { get; set; }
}
You can then run
RootObject obj = JsonConvert.DeserializeObject<RootObject>(data);
to deserialise it.
/* method arguments:
stream : Stream class instance
charSet: Character set (in string), default is current system encoding.
bufferSize: Buffer size, default 1024 bytes
*/
static async Task<string> readStreamAsync(Stream stream, string charSet = "", int bufferSize = 1024)
{
/* read stream to buffers */
var buffer = new byte[bufferSize];
List<byte> buffers = new List<byte>();
using (var readStream = new StreamReader(stream))
{
// read stream into buffer
var n = await readStream.ReadAsync(buffer, 0, bufferSize);
// loop buffer streaming until no more stream data
while (n > 0)
{
// populate buffer into buffer list
buffers.AddRange(new ArraySegment<byte>(buffer, 0, n).Array);
// read stream into buffer
n = await readStream.ReadAsync(buffer, 0, bufferSize);
}
}
/* return encoded string */
if (String.IsNullOrWhiteSpace(charSet))
{
// encode buffers array into default encoded string
return Encoding.Default.GetString(buffers.ToArray());
}
else
{
// encode buffers array into encoded string based on any character set
return Encoding.GetEncoding(charSet).GetString(buffers.ToArray());
}
}
/* usage: */
string data;
try
{
using (var receiveStream = response.GetResponseStream())
{
data = await readStreamAsync(receiveStream, response.CharacterSet);
}
}
finally
{
response.Close();
}
Console.WriteLine(data);
Statistic statistic = JsonConvert.DeserializeObject<Statistic>(data);
I'm new to Xamarin so please excuse me .I have a json object I'm trying to deserialize it using refit but I think the error appears because of the class is not correct
This is the json object
{
"status": true,
"message": null,
"data": [
{
"menu_id": 46,
"menu_title": "media",
"menu_parent": 0,
"menu_sort": "1",
"menu_status": "1",
"courses_count": 4,
"subCat": [
{
"menu_id": 48,
"menu_title": "media",
"menu_parent": 46,
"menu_sort": "1",
"courses_count": 0,
"menu_status": "1",
"subCat": [
{
"menu_id": 50,
"menu_title": "media",
"menu_parent": 48,
"menu_sort": "1",
"courses_count": 0,
"menu_status": "1",
"subCat": []
},
{
"menu_id": 51,
"menu_title": "media",
"menu_parent": 48,
"menu_sort": "1",
"courses_count": 0,
"menu_status": "1",
"subCat": []
}
]
},
{
"menu_id": 49,
"menu_title": "media",
"menu_parent": 46,
"menu_sort": "1",
"courses_count": 0,
"menu_status": "1",
"subCat": []
}
]
},
{
"menu_id": 47,
"menu_title": "media",
"menu_parent": 0,
"menu_sort": "2",
"menu_status": "1",
"courses_count": 2,
"subCat": []
},
{
"menu_id": 55,
"menu_title": "CS",
"menu_parent": 0,
"menu_sort": "3",
"menu_status": "1",
"courses_count": 2,
"subCat": []
}
]
}
I used json2csharp to convert the json and that's what I get
public class Datum
{
public int menu_id { get; set; }
public string menu_title { get; set; }
public int menu_parent { get; set; }
public string menu_sort { get; set; }
public string menu_status { get; set; }
public int courses_count { get; set; }
public List<object> subCat { get; set; }
}
public class RootObject
{
public bool status { get; set; }
public object message { get; set; }
public List<Datum> data { get; set; }
}
and this is the code using refit
the interface
public interface IGDGAPI
{
[Get("/category")]
Task<List<RootObject>> GetCategories();
}
the code
var apiResponce = RestService.For<IGDGAPI>("API Link Here");
var Categs = await apiResponce.GetCategories();
CategList.ItemsSource = _categs;
when I insert a breakpoint at Categs it gives me null
and this is the error message
Unhandled Exception:
Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'GDG6OCT.Models.RootObject[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'status', line 1, position 10.
This is what I used to solve it if someone came across the same problem I didn't use refit just used regular HTTP requests and NewtonSoft for Json
The Model
public class Category
{
public bool status { get; set; }
public object message { get; set; }
public IList<Datum> data { get; set; }
}
public class SubCat
{
public int menu_id { get; set; }
public string menu_title { get; set; }
public int menu_parent { get; set; }
public string menu_sort { get; set; }
public int courses_count { get; set; }
public string menu_status { get; set; }
public IList<object> subCat { get; set; }
}
public class Datum
{
public int menu_id { get; set; }
public string menu_title { get; set; }
public int menu_parent { get; set; }
public string menu_sort { get; set; }
public string menu_status { get; set; }
public int courses_count { get; set; }
public IList<SubCat> subCat { get; set; }
}
}
The API Call Request
async Task CallApi()
{
string Url = "your Link Goes Here";
HttpResponseMessage response;
string return_value = "empty";
try
{
HttpClient _client = new HttpClient();
response = await _client.GetAsync(Url);
if (response.IsSuccessStatusCode)
{
return_value = await response.Content.ReadAsStringAsync();
var categs = JsonConvert.DeserializeObject<Category>(return_value).data;
CategList.ItemsSource = categs;
}
else
{
return_value = "not successful";
}
}
catch (Exception ex)
{
return_value = (string)ex.Message + " :: " + ex.InnerException.Message;
}
}
You should try to deserialize the JSON into a JObject then access its properties by keys:
var obj = JsonConvert.DeserializeObject<JObject>("Json content as a string");
var prop1 = obj["Key1"];
var prop2 = obj["key2"]["subkey"];
You are trying to deserialize a list, however you are receiving one RootObjet.
Change this:
[Get("/category")]
Task<RootObject> GetCategories();
In my case I was not getting any feedback from my debugger, no errors just a blank object. What worked for me was to initialize the object you want to deserialize into before the Get call.
For this example (using Refit) it would be something like:
var rootObject = new RootObject();
var apiResponse = RestService.For<IGDGAPI>("API Link Here");
rootObject = await apiResponse.GetCategories();
I have the class below:
public class Product
{
[JsonProperty("image")]
public string ImageURL { get; set; }
[JsonProperty("superDepartment")]
public string SuperDepartment { get; set; }
[JsonProperty("tpnb")]
public long TPNB { get; set; }
[JsonProperty("ContentsMeasureType")]
public string ContentsMeasureType { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("UnitOfSale")]
public int UnitOfSale { get; set; }
[JsonProperty("description")]
public IEnumerator<string> LstDescription { get; set; }
public string Description { get; set; }
[JsonProperty("AverageSellingUnitWeight")]
public decimal AverageSellingUnitWeight { get; set; }
[JsonProperty("UnitQuantity")]
public string UnitQuantity { get; set; }
[JsonProperty("id")]
public long ID { get; set; }
[JsonProperty("ContentsQuantity")]
public int ContentsQuantity { get; set; }
[JsonProperty("department")]
public string Department { get; set; }
[JsonProperty("price")]
public decimal Price { get; set; }
[JsonProperty("unitprice")]
public decimal UnitPrice { get; set; }
}
I have the method on the productController:
public async Task<ActionResult> MakeRequest(string q)// worked
{
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "56ac439a92694577a2779f3d0ee0cd85");
var uri = string.Format("https://dev.tescolabs.com/grocery/products/?query={0}&offset={1}&limit={2}", q, 0, 10);
var response = await client.GetAsync(uri);
string body = await response.Content.ReadAsStringAsync();
Product myoutput = JsonConvert.DeserializeObject<Product>(body);
}
return View(body);
}
and I have the model below:
For some reason when I call the method MakeRequest it just shows the information as a string and an error saying Server Error as per picture below we can see the information from the api but it is showing as a string.
error message
The information from the api it should be showing on the table below:
table
How to show the data on the table? Or better how to convert the json array to a net object?
I know there is something missing in the part below of my method:
Product myoutput = JsonConvert.DeserializeObject<Product>(body);
You're passing json string to your View instead of your deserialized Product.
I assume your View expects model of type Product.
The return statement of MakeRequest action should be return View(myOutput);
I'll tell you in a simple way.
Your json model
-uk
--ghs
---products
----results
{
"uk" : {
"ghs" : {
"products": {
"input_query": "babana",
"output_query": "banana",
"filters": {},
"queryPhase": "post_primary",
"totals": {
"all": 109,
"new": 1,
"offer": 47
},
"config": "default",
"results": [
{
"image": "http://img.tesco.com/Groceries/pi/000/0261480000000/IDShot_90x90.jpg",
"superDepartment": "Fresh Food",
"tpnb": 50502269,
"ContentsMeasureType": "KG",
"name": "Tesco Bananas Loose",
"UnitOfSale": 3,
"description": [ "To help ensure the banana farms we source from are best in class we, and our", "suppliers, now work closely with the Rainforest Alliance, an international", "non profit organisation that works to conserve biodiversity and ensure", "sustainable livelihoods worldwide.", "The Rainforest Alliance Certified™ seal on our bananas a green frog nestled", "in a circle – helps us to tell the story of how they are sustainably sourced,", "and assure customers we are sourcing from responsibly managed farms." ],
"AverageSellingUnitWeight": 2.402,
"UnitQuantity": "KG",
"id": 275280804,
"ContentsQuantity": 1,
"department": "Fresh Fruit",
"price": 0.76,
"unitprice": 0.76
},
{
"image": "http://img.tesco.com/Groceries/pi/875/0000010001875/IDShot_90x90.jpg",
"superDepartment": "Fresh Food",
"tpnb": 65728590,
"ContentsMeasureType": "SNGL",
"name": "Tesco Ripe Bananas 5 Pack",
"UnitOfSale": 1,
"AverageSellingUnitWeight": 0.862,
"UnitQuantity": "EACH",
"id": 266419328,
"ContentsQuantity": 5,
"department": "Fresh Fruit",
"price": 0.9,
"unitprice": 0.18
},
{
"image": "http://img.tesco.com/Groceries/pi/416/0000003251416/IDShot_90x90.jpg",
"superDepartment": "Fresh Food",
"tpnb": 77427870,
"ContentsMeasureType": "SNGL",
"name": "Tesco Small Bananas 6 Pack",
"UnitOfSale": 1,
"description": [ "Small Bananas", "Tesco Small Bananas" ],
"AverageSellingUnitWeight": 0.965,
"UnitQuantity": "EACH",
"id": 285157326,
"ContentsQuantity": 6,
"department": "Fresh Fruit",
"price": 0.9,
"unitprice": 0.15
}
],
"suggestions": []
}
}
}
}
If you look at the above json result, you need a more comprehensive model.
For this you can enter the json result into a model here. look here
or keep the result object from its current state with dynamic.
string body = response.Content.ReadAsStringAsync().Result;
dynamic content = JObject.Parse(body);
var products = content.uk.ghs.products.results;