How can I convert String to a Dictionary(Of String, String())?

Hi everyone,

I want to assign my string variable “DictStatusWert” with the following value:

New Dictionary(Of String,String())From{{“010”,{“gesperrt”,“in Erstellung”,“im Hintergrund”,“in Bearbeitung”,“fehlerhaft”,“neu”}}}

… to my dictionary(Of String, String()) “DictStatus”.

How can I do that?

Thanks in advance,
Dennis :slight_smile:

Hi @bibalesecret,

Please try this assign. With this assign, “010” is key and “gesperrt” is the value. Please change the double quotes, when you copy this statement to your workflow.

New Dictionary(Of String,String)From{{“010”,“gesperrt”},{“in Erstellung”,“im Hintergrund”},{“in Bearbeitung”,“fehlerhaft”}}

Regards
Ömer

Thanks for your reply.

But I meant that I already have the value in my string variable “DictStatusWert”.
I want to convert the String Variable “DictStatusWert” to my Dictionary(Of String, String()) “DictStatus” in an Assign-Activity :wink:

Hi @bibalesecret ,

Could you maybe provide an Example of the Data before and after the Conversion to a Dictionary ?

Are you trying to convert a String type variable to a Dictionary type during Runtime/ while execution ?

I have the value: New Dictionary(Of String,String())From{{“010”,{“gesperrt”,“in Erstellung”,“im Hintergrund”,“in Bearbeitung”,“fehlerhaft”,“neu”}}} in a Excel Cell.
I read it with a read cell value activity and save it to the string variable “DictStatusWert”.
After that I want to work with my Dictionary(Of String, String()) “DictStatus”. Before that, I want to convert my String Variable to my Dictionary(Of String, String()).

For example:
Assign to: DictStatus
Assign From: DictStatusWert.toDictionary(Of String, String()).

But this syntax isn’t working for me, because the follwing error appears:
Overload resolution failed because no accesible ‘ToDictionary’ accepts this number of arguments.

maybe you are looking for this:
DictStatusWert.toDictionary(Function (x) x.Key, Function (x) x.Value)

when using the toDictionary we will tell what to use for the key and value

Close, but I dont want to get any value from the dictionary.
Maybe I misunderstood the syntax “toDictionary”.
In general, I just want to fill in the default value out of my excel cell to DictStatus :wink:

There are some doubts as the description is not fully clear and can be interpreted in different directions

is it about adding / storing?

dictRawStrings(“myKeyFor110”) = myStringFromExcelCell

otherwise help us for understanding by showing on text / pseudo

what is excel value
what is the expected DictStatusWert when Excel String is processed
what is to achieve and resulting DictStatus

I have the value: “New Dictionary(Of String,String())From{{“010”,{“gesperrt”,“in Erstellung”,“im Hintergrund”,“in Bearbeitung”,“fehlerhaft”,“neu”}}}” in a Excel Cell.
I read it with a read cell value activity and save it to the string variable “DictStatusWert”.
After that I want to work with my Dictionary(Of String, String()) “DictStatus”. Before that, I want to convert my String Variable to my Dictionary(Of String, String()).
So that my Dictionary “DictStausWert” has the Default Value:
New Dictionary(Of String,String())From{{“010”,{“gesperrt”,“in Erstellung”,“im Hintergrund”,“in Bearbeitung”,“fehlerhaft”,“neu”}}}

when this string from excel
“New Dictionary(Of String,String())From{{“010”,{“gesperrt”,“in Erstellung”,“im Hintergrund”,“in Bearbeitung”,“fehlerhaft”,“neu”}}}”

should be used as VBCode code then you are blocked as compiling cannot be bypassed

How about:

  • stroring dictionaray as JSON String
    "{'010':['gesperrt','in Erstellung','im Hintergrund','in Bearbeitung','fehlerhaft','neu']}"

Deserializing it to a dictionary

Newtonsoft.Json.JsonConvert.DeserializeObject(Of Dictionary(of String, String()))("{'010':['gesperrt','in Erstellung','im Hintergrund','in Bearbeitung','fehlerhaft','neu']}")
2 Likes

That worked.
But what If I have more value in my excel cell like the following:

New Dictionary(Of String,String())From{{“010”,{“gesperrt”,“in Erstellung”,“im Hintergrund”,“in Bearbeitung”,“fehlerhaft”,“neu”}},{“100”,{“Blokov.”,“ve zpracování”,“Na Pozadí”,“ve zpracování (in work)”,“Chybné”,“Nové”}}}


When I change it into this:

{‘010’:[‘gesperrt’,‘in Erstellung’,‘im Hintergrund’,‘in Bearbeitung’,‘fehlerhaft’,‘neu’]},{‘100’:{‘Blokov.’,‘ve zpracování’,‘Na Pozadí’,‘ve zpracování (in work)’,‘Chybné’,‘Nové’}]

It does not work, because "the additional text encuntered after finished reading JSON content: ,.Path “, line 1, position 89”

then the JSON will look like this

"{ 
    '010':['gesperrt','in Erstellung','im Hintergrund','in Bearbeitung','fehlerhaft','neu'], 
    '100':['Blokov.','ve zpracování','Na Pozadí','ve zpracování (in work)','Chybné','Nové'] 
}"

grafik

1 Like

kindly note the wrong endings:

and ensure that ' is used and not `or ´

1 Like

thank you, peter!

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