I find it difficult to write the appropriate annotations to represent the data that is returned from the JSON Get request, which returns the data as follows:
[{"ProductCode":"0129923083091","Description":"DIESEL ","SalesLitres":6058.7347,"SalesValue":6416.2000},{"ProductCode":"0134039344902","Description":"UNLEADED ","SalesLitres":3489.8111,"SalesValue":3695.7100}, ... ]
(the ellipsis above just indicating that I could have a variable number of these elements)
In my model class (I use the MVVM approach for the Xamarin project, but itβs not so important) I use annotations to represent the attributes of the model
namespace App8.Models { public class ReportRow { [JsonProperty("ProductCode")] public string ProductCode { get; set; } = string.Empty; [JsonProperty("Description")] public string Description { get; set; } = string.Empty; [JsonProperty("SalesLitres")] public double SalesLitres { get; set; } = 0.0; [JsonProperty("SalesValue")] public double SalesValue { get; set; } = 0.0; } }
I would like to point out another class that shows the container / contained ratio. However, I'm looking up because the annotation does not have a JSON attribute to represent the "root" of the returned collection.
I would not have a problem displaying JSON in the object model for any JSON arrays that are called in the returned JSON. In this case, I could create another class with the specified JSON attribute that contained the C # list, but I am trying to provide an appropriate model mapping for JSON that returns a list of elements in an unnamed array.
Any ideas how I could approach this?
source share