I am able to bind the top level json parameter but not the nested ones. What am I missing? The nested one are completely ignored.
Code:
IEnumerable<coupaPO> empobj = null;
HttpClient hc = new HttpClient();
hc.DefaultRequestHeaders.Add("X-API-KEY", "XXXXXXXXXXXXXXXX");
hc.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));//ACCEPT header
hc.BaseAddress = new Uri("https://company.com/api/");
var comsumeapi = hc.GetAsync("purchase_orders?id=1234");
comsumeapi.Wait();
var readdata = comsumeapi.Result;
if (readdata.IsSuccessStatusCode)
{
var displayrecords = readdata.Content.ReadAsAsync<IList<coupaPO>>();
displayrecords.Wait();
empobj = displayrecords.Result;
GridView1.DataSource = empobj;
GridView1.DataBind();
// [...]
}
Classes: I have created classes for each json level and nested it with the class I'm binding to the gridview.
public partial class coupaPO
{
[JsonProperty("po-number")]
public string PONumber { get; set; }
[JsonProperty("created-at")]
public DateTime CreatedAt { get; set; }
[JsonProperty("ship-to-attention")]
public string ShipToAttention { get; set; }
[JsonProperty("erp-po-number")]
public string erpponumber { get; set; }
[JsonProperty("buyer")]
public Buyer Buyer { get; set; }
}
public partial class Buyer
{
[JsonProperty("email")]
public string Email { get; set; }
[JsonProperty("fullname")]
public string Fullname { get; set; }
[JsonProperty("custom-fields")]
public CustomFields CustomFields { get; set; }
}
public partial class CustomFields
{
[JsonProperty("po2go")]
public string Po2Go { get; set; }
}
EDIT: I'm adding the JSON file. it is a portion of the one I receive from 3rd party vendor.
The Gridview columns are being auto-generated
{
"id": 475652,
"created-at": "2020-03-04T15:12:20-05:00",
"po-number": "C000475652",
"ship-to-attention": "Kim Willis",
"coupa-accelerate-status": null,
"change-type": "revision",
"transmission-method-override": "supplier_default",
"transmission-emails": "",
"buyer": {
"id": 3104,
"email": "Azy.Lag@company.com",
"fullname": "Azy Lag",
"salesforce-id": null,
"avatar-thumb-url": null,
"buyer": "",
"el-self-approval": false,
"custom-fields": {
"po2go": ""
}
},
}