Maintain Order in JSON Import
Sannyasin Brahmanathaswami
brahma at hindu.org
Mon Sep 12 17:23:57 EDT 2016
If you import JSON like this:
{
"colormeds": {
"progress": {
"level": "1",
"cycle": "1"
},
"colorwheel": {
"Red": "255,0,0",
"Red-Orange": "255,64,0",
"Orange": "255,127,0",
"Orange-Yellow": "255,191,0",
"Yellow": "255,255,0",
"Yellow-Green": "191,255,0",
"Green": "0,255,0",
"Green-Blue": "0,191,255",
"Blue": "0,0,255",
"Blue-Violet": "127,0,255",
"Violet": "127,0,127",
"Red-Violet": "191,0,127"
}
}
the keys for:
sConfigColor["colormeds"]["colorwheel"] are returned as expected in a hashed order
Blue
Orange-Yellow
Violet
Green
Green-Blue
Red-Violet
Blue-Violet
Red
Yellow
Red-Orange
Orange
Yellow-Green
is there a simple method for restoring the sequential order as entered in the JSON? or a way to store in the JSON that facilitates that requirement?
I solved it by put the values into an array, with a extra delimited, but this seems "hacky" but can now order the keys because they default to numeric index
"colorwheel": [
"Red|255,0,0",
"Red-Orange|255,64,0",
"Orange|255,127,0",
"Orange-Yellow|255,191,0",
"Yellow|255,255,0",
"Yellow-Green|191,255,0",
"Green|0,255,0",
"Green-Blue|0,191,255",
"Blue|0,0,255",
"Blue-Violet|127,0,255",
"Violet|127,0,127",
"Red-Violet|191,0,127"]
},
Now I have to set the delimiter to pipe and then fetch the item…
Is there a better way?
More information about the use-livecode
mailing list