Cast complex deserialized  Json object to enumerable so that it can be bound to an a gridview

kriskyk
kriskyk used Ask the Experts™
on
I need to understand how to cast a complex deserialized  Json object to enumerable so that it can be bound to an a gridview

           var enumerable = new[] { GetBuilds().Result};
                       

            GridView1.DataSource = enumerable;
            GridView1.DataBind();

Open in new window




2020-01-13_11-28-21.png


Currently it only results in the top node, i need to get the data in the fields node.

2020-01-13_11-29-37.png
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Architect - Coder - Mentor
Commented:
Hi,

Try to create a List<T> from GetBuilds().Result, where T is the type of the elements contained in the Result.

var enumerable = new List<>(GetBuilds().Result);
GridView1.DataSource = enumerable;
 GridView1.DataBind();

Author

Commented:
End up with the following:

            dynamic DevOpsJSONObj = GetWorkItems.GetWorkItemsz().Result;

            List<DevOpsWorkItems> items = new List<DevOpsWorkItems>();

            for (int i = 0; i < DevOpsJSONObj.Count; i++)
            {
                items.Add(new DevOpsWorkItems
                {
                    ID = DevOpsJSONObj.Value[i].Fields.SystemId,
                    Title = DevOpsJSONObj.Value[i].Fields.SystemTitle,
                    WorkItemType = DevOpsJSONObj.Value[i].Fields.SystemWorkItemType,
                    State = DevOpsJSONObj.Value[i].Fields.SystemState,
                    Created = DevOpsJSONObj.Value[i].Fields.SystemCreatedDate,
                    CreatedBy = DevOpsJSONObj.Value[i].Fields.SystemCreatedBy.DisplayName,
                    Modified = DevOpsJSONObj.Value[i].Fields.SystemChangedDate,
                    ModifiedBy = DevOpsJSONObj.Value[i].Fields.SystemChangedBy.DisplayName
                });
            }
                       

Open in new window

Eduard GherguArchitect - Coder - Mentor

Commented:
Hi,

Ok, it's good that it's working. Could you award my answer and close the question? Thank you!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial