What is the proper way to parse row data to something readable?

Matt 20 Reputation points
2025-06-20T22:54:01.93+00:00

I am trying to get some information in the rows of a spreadsheet I am writing to, But having trouble trying to figure it out. Everything works to the point of GetValue() on the unknownString. It is still coming back as an UntypedArray. How do I go about getting this value if its unknown? I am only using strings and integers but neither of those work.

public async Task<List<string>> GetRowData()
{
    var rowsAsStrings = new List<string>();

    var rows = await GraphClient.Drives[driveId].Items[documentId].Workbook.Tables[tableId].Rows.GetAsync();

    //Debug.Log(rows.Value.Count); // Returns correct amount of rows
    
    if (rows?.Value != null)
    {
        foreach (var row in rows.Value)
        {
            //Debug.Log(row.Values); // Returns Microsoft.Kiota.Abstractions.Serialization.UntypedArray 
            
            if (row.Values is UntypedArray cellsArray)
            {
                foreach (var cellValueNode in cellsArray.GetValue()) 
                {
                    if (cellValueNode is UntypedString stringValue)
                    {
                        Debug.Log("Add String"); // Never gets called
                        rowsAsStrings.Add(stringValue.GetValue());
                    }
                    else if (cellValueNode is UntypedInteger intValue)
                    {
                        Debug.Log("Add Integer"); // Never gets called
                        rowsAsStrings.Add(intValue.GetValue().ToString());
                    }
                    else if (cellValueNode is not null)
                    {
                        Debug.Log("Add Unknown"); // Gets called
                        var unknownString = (UntypedNode)cellValueNode;
                        rowsAsStrings.Add(unknownString.GetValue().ToString()); // NotImplementedException: The method or operation is not implemented.
                    }
                }
            }
        }
    }

    return rowsAsStrings;
}


public async void GetRowData()
        {
           var rows = await _graphHandler.GetRowData();

           foreach (var row in rows)
           {
               Debug.Log(row); // Returns Microsoft.Kiota.Abstractions.Serialization.UntypedArray
           }

        }

Developer technologies C#
{count} votes

2 answers

Sort by: Most helpful
  1. Ripin 11 Reputation points
    2025-06-21T05:29:02.8866667+00:00

    Some time back, we also have faced the similar issue. With below workaround, we were able to serialize and then deserialize the data from an UntypedArray.

    Ensure transitive dependencies for Microsoft.Kiota.Abstractions specify 1.8.3 instead of the default 1.8.0.

    • Serialize the Kiota object after casting to kiota untyped types (we treat all additionaldata as dictionary<string, object>) ie String sJSON = KiotaJsonSerializer.SerializeAsString((UntypedArray)dsoData.Value);

    Deserialize JSON as needed..

    The key was to get the right nuget reference since 1.8.0 does not have this. I think 5.47.0+ graph sdk installs should require 1.8.3 Kiota abstractions, or whichever minimum version first provided for UntypedArray. It is still a breaking change that should be documented better in nuget/release notes.

    1 person found this answer helpful.
    0 comments No comments

  2. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2025-06-21T18:00:50.4666667+00:00

    you need to use recursion to get the scalar value. see ParseUntypedNode example in:

    https://learn.microsoft.com/en-us/openapi/kiota/serialization?tabs=csharp

    air code - return flattened list:

    
    private static List<string> ParseUntypedNode(UntypedNode untypedNode)
    {
        var list = new List<string>();   
        switch (untypedNode)
        {
            case UntypedObject untypedObject:
                foreach (var (name, node) in untypedObject.GetValue())
                {
                     list.AddRange(ParseUntypedNode(node));// handle the nested nodes
                }
                break;
    
            case UntypedArray untypedArray:
                foreach (var item in untypedArray.GetValue())
                {
                     list.AddRange(ParseUntypedNode(item));// handle the nested nodes
                }
                break;
    
            case UntypedString:
            case UntypedBoolean:
            case UntypedDouble:
            case UntypedFloat:
            case UntypedInteger:
            case UntypedLong:
            case UntypedNull:
                string scalarAsString = KiotaJsonSerializer.SerializeAsString(untypedNode);
                list.Add(scalarAsString);
                break;
        }
        return list;
    }
    
    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.