I am in the process of converting a dynamic JSON object into Excel in C#. I have tried the below steps. From the DB, I am getting the below response as a string.
[ {"ResourceName":"AH","ProjectID":1,"WeekNo":2,"02 Dec 2019":7.00,"03 Dec 2019":7.50,"04 Dec 2019":7.00,"05 Dec 2019":7.50,"06 Dec 2019":7.00},{"ResourceName":"CK","ProjectID":1,"WeekNo":2,"02 Dec 2019":6.00,"03 Dec 2019":5.00,"04 Dec 2019":3.00,"05 Dec 2019":2.00,"06 Dec 2019":5.00}, {"ResourceName":"AH","ProjectID":1,"WeekNo":3,"09 Dec 2019":6.00,"10 Dec 2019":7.50,"11 Dec 2019":7.00,"12 Dec 2019":7.50,"13 Dec 2019":8.00},{"ResourceName":"CK","ProjectID":1,"WeekNo":3,"09 Dec 2019":6.00,"10 Dec 2019":4.00,"11 Dec 2019":null,"12 Dec 2019":5.00,"13 Dec 2019":4.00},{"ResourceName":"SL","ProjectID":1,"WeekNo":3,"09 Dec 2019":null,"10 Dec 2019":1.50,"11 Dec 2019":null,"12 Dec 2019":1.50,"13 Dec 2019":0.50}, {"ResourceName":"AH","ProjectID":1,"WeekNo":4,"16 Dec 2019":7.00},{"ResourceName":"CK","ProjectID":1,"WeekNo":4,"16 Dec 2019":3.00} ]
I am required to convert the above string to a JSON and do a loop operation in order to set headers and detail values for Excel creation. I have used the below method creating a dynamic
object.
ResourceName and dynamic dates should act as column headers. It is unable to create a model since the date
values are dynamic.
using System.Web.Helpers;
dynamic jsonObject = Json.Decode(response);
I was able to extract the values from QuickWatch, however, the output is only generated in runtime as below.
(new System.Collections.Generic.Mscorlib_DictionaryDebugView<string, object>(((System.Web.Helpers.DynamicJsonObject)((System.Web.Helpers.DynamicJsonArray)jsonObject)._arrayValues[0])._values).Items[0]).Key
Is there a way to loop through the dynamic array contents?