Work with Nested Dictionary / Array

Shaykid

New member
Hello
I have a dictionary I make with JSON parse (Great feature !!)
This is a nested dictionary, each key points to a dictionary (stored in the value)
I want to make this root dictionary into array, (array cell index = integer, cell value = inner dictionary)
I try to Iterate the root dictionary, but i cant find a way to put the iterator_value into the array cell (or iterate loop on the previous [iterator_value])
Is there a way to do it ?

This is how my JSON looks like:
{
"123000" : {
"Code" : "555",
"Done" : "false",
"Group" : "099",
"Lap" : "10",
"Media" : "",
"MinTime" : "0",
"Text" : "הכל משמיים",
"Type" : "W" },
"123001" : {
"Code" : "556",
"Done" : "false",
"Group" : "099",
"Lap" : "10",
"Media" : "",
"MinTime" : "0",
"Text" : " פעמיים הכל משמיים",
"Type" : "W" }
}

Thanx in advance,
 

dsnz

Well-known member
haha , I got your point :)

it's the way MD works with screens and checking available variables
so.. it's not possible in a loop to assign to a dictionary variable the iterator value
and so it's impossible to have a nested loop

even if @MacroDroidDev finds a workaround...
this post of mine

Post in thread 'voice input works with variables of type dict but not array' http://www.macrodroidforum.com/inde...es-of-type-dict-but-not-array.2355/post-13380

is very relevant as the combinations and nestings of data containers are so many that it's impossible to handle with configuration screens
 

reThink23

New member
If I understand it correctly it is possible, but the solution is ugly. You could rewrite the json string with text manipulation (replace all with regex) to bring the data in such form:
{ "data": [
{
"Code" : "555",
"Done" : "false",
"Group" : "099",
"Lap" : "10",
"Media" : "",
"MinTime" : "0",
"Text" : "הכל משמיים",
"Type" : "W" },
{
"Code" : "556",
"Done" : "false",
"Group" : "099",
"Lap" : "10",
"Media" : "",
"MinTime" : "0",
"Text" : " פעמיים הכל משמיים",
"Type" : "W" }
]}

And then copy the parsed array of data into another array.
For the regex part I used two.
First to make it arrays:
Regex: ^\{((.|\n)*)\}
Explanation: select everything but preserve everything between the outer most brackets.
Replace: { "data": [$1]} put the preserved text into brackets and create a key "data" to get access to it.
Second to remove the keys.
Regex: "\d+" :
Replace: (a whitespace)
Explanation: remove the number keys and the semicolon.

Then parse it with JSON and create array which copies json["data"]
 

Attachments

  • forum_question.macro
    10.5 KB · Views: 13
Top