Hi,
I am at a point to store some data and like to use JSON format,
combined with maps into a file.
The flow creates the map:
cMap=newMapFromValues("triggertime",triggertime,"name","Martin","phone","+486145558","info","Info");
js=toJSON(cMap);
The action stores the variable js into the file, all OK.
Next time the flow starts I read the stored map, do a
cMap=from JSON(var);
Now I want to have the next data
cMap1=newMapFromValues("triggertime",triggertime,"name","Desmanto","phone","+626163451","info","Info1");
combined with cMap, stored as JSON again in the file, so now there are 2 records.
How to add cMap and cMap1?
Thanks a lot,
Regards,
Maps and JSON tofile fromfile
Moderator: Martin
Maps and JSON tofile fromfile
"You cannot know the meaning of your life until you are connected to the power that created you.”
Shri Mataji Nirmala Devi, founder of Sahaja Yoga
Shri Mataji Nirmala Devi, founder of Sahaja Yoga
Re: Maps and JSON tofile fromfile
There are 2 ways
1st method
Create a list and store cMap in it.
2nd method
Create only one cMap and create every key as List.
Now when you need to add an entry do like this
1st method
Create a list and store cMap in it.
Code: Select all
cList=newList();
cMap=newMapFromValues("triggertime",triggertime,"name","Martin","phone","+486145558","info","Info");
addElement(cList, cMap);
cMap1=newMapFromValues("triggertime",triggertime,"name","Desmanto","phone","+626163451","info","Info1");
addElement(cList, cMap1);
js=toJSON(cList);
Create only one cMap and create every key as List.
Code: Select all
cMap=newMapFromValues(
"triggertime", newList(),
"name", newList(),
"phone", newList(),
"info", newList());
Code: Select all
addElement(cMap['triggertime'], triggertime);
addElement(cMap['name'], "Martin");
addElement(cMap['phone'], "+486145558");
addElement(cMap['info'], "info");
js=toJSON(cMap)
Re: Maps and JSON tofile fromfile
Hi,
It seems to be the 2nd solution I prefer.
Thanks a lot,
Regards
[edit]
after some tests I am at the 1st solution now, got it working
It seems to be the 2nd solution I prefer.
Thanks a lot,
Regards
[edit]
after some tests I am at the 1st solution now, got it working
"You cannot know the meaning of your life until you are connected to the power that created you.”
Shri Mataji Nirmala Devi, founder of Sahaja Yoga
Shri Mataji Nirmala Devi, founder of Sahaja Yoga
Re: Maps and JSON tofile fromfile
First solution is better, as you always keep adding the map to the end of the list, no need to care about the key map (cMap1, cMap2, ....)
For 2nd solution, you can create the map as you do (cMap1), and then add the map.
cMap["cMap1"] = cMap1;
This will create the nested map with the key cMap1, cMap2, .... and so on. But might be quite confusing, so better solution 1.
For 2nd solution, you can create the map as you do (cMap1), and then add the map.
cMap["cMap1"] = cMap1;
This will create the nested map with the key cMap1, cMap2, .... and so on. But might be quite confusing, so better solution 1.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.