How to initialize Array of dictionary?

Hi there,

How do you initialize an Array of Dictionary?

I have tried New Dictionary(Of string,string){} but this displays as an error. Have tried other variations but no luck.

new Dictionary(Of string,string)() will create an empty array of Dictionary(Of String, String)

Hi @Jon_G

If you want to Initialize the Dictionary,

New Dictionary(Of String, String)

If you want to Initialize the List of Dictionary,

New List(Of Dictionary(Of String, String))()

Hope it helps!!

1 Like

grafik

In addition to above, initialiing the array with an empty initialized empty Dictionary we can do

grafik

Thanks for the quick response, however still not having any luck with this, the syntax seems correct but I still see an error on the Assign activity. Not sure if my variable is wrong or something?

I’ve entered here: New Dictionary(Of string,string)()

Btw the reason I need multiple dictionaries is because I am parsing an API response which may include 1 or many payloads, so I need to put each payload into its own dictionary of key/value pairs.

RnD and prototyping can be done within the immediate panel (as shown above)
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

About the exception, please share with us the Variable definition and modelling details

Hello @Jon_G

Did you Declare the Array Dictionary Like this ?

If so, You have to intialize it like this:

New Dictionary(Of String, String)() {}

Screenshot from Variables Panel:

If this solves your issue, Do mark it as a solution
Happy Automation :star_struck:

2 Likes

My variable in the panel is displayed as:

System.Collections.Generic.Dictionary<System.String, System.String>

Hi @Jon_G
Please check my solution

1 Like

Thankyou! That works

The solution was so simple I was just missing both the brackets (){}

Great to know and hopefully this helps anyone else :slight_smile:

1 Like

Thanks this did also work if I was to store it as a List, however, I was able to follow a different solution to use Array still :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.