How to sort a structured list?

Just starting out? Need help? Post your questions and find answers here.
Dirk Geppert
Posts: 333
Joined: Fri Sep 22, 2017 7:02 am

How to sort a structured list?

Post by Dirk Geppert »

Hello,

unfortunately SB does not support sorting a structured list.
Is there a way to do this with Javascript?

Otherwise I consider to copy the list into a map and use the element to be sorted as key.

And then to sort the keys with a simple list...

What do you think?
Dirk Geppert
Posts: 333
Joined: Fri Sep 22, 2017 7:02 am

Re: How to sort a structured list?

Post by Dirk Geppert »

I just noticed that the sort order can change during JSON include and extract.
Now I have a real problem :roll: ...and could need a SortStructuredList.
User avatar
Kurzer
Posts: 96
Joined: Mon May 26, 2014 9:33 am

Re: How to sort a structured list?

Post by Kurzer »

Jupp, that's the reason why I glue my JSON string manually by hand in a ForEach loop.

Code: Select all

#JSON_Header = "{" + #EOL +
	               "  'mpLayouts':{" + #EOL
	#JSON_Layout = "    'xLayoutName':{" + #EOL +
	               "      'iAutoSwitchWidth':xiAutoSwitchWidth," + #EOL +
	               "      'iAutoSwitchHeight':xiAutoSwitchHeight," + #EOL +
	               "      'iWidth':xiWidth," + #EOL +
	               "      'sWidthMode':'xsWidthMode'," + #EOL +
	               "      'iHeight':xiHeight," + #EOL +
	               "      'sHeightMode':'xsHeightMode'," + #EOL +
	               "      'iMarginLeft':xiMarginLeft," + #EOL +
	               "      'sMarginLeftMode':'xsMarginLeftMode'," + #EOL +
	               "      'iMarginTop':xiMarginTop," + #EOL +
	               "      'sMarginTopMode':'xsMarginTopMode'," + #EOL +
	               "      'iMarginRight':xiMarginRight," + #EOL +
	               "      'sMarginRightMode':'xsMarginRightMode'," + #EOL +
	               "      'iMarginBottom':xiMarginBottom," + #EOL +
	               "      'sMarginBottomMode':'xsMarginBottomMode'," + #EOL +
	               "      'sHorizontalAlignment':'xsHorizontalAlignment'," + #EOL +
	               "      'sVerticalAlignment':'xsVerticalAlignment'," + #EOL +
	               "      'sLayoutFont':'xsLayoutFont'," + #EOL +
	               "      'mpLayoutItem':{" + #EOL
	#JSON_LayoutItem = "        'xLayoutItemName':{" + #EOL +
	                   "          'iX1':xiX1," + #EOL +
	                   "          'sX1Mode':'xsX1Mode'," + #EOL +
	                   "          'iY1':xiY1," + #EOL +
	                   "          'sY1Mode':'xsY1Mode'," + #EOL +
	                   "          'iX2':xiX2," + #EOL +
	                   "          'sX2Mode':'xsX2Mode'," + #EOL +
	                   "          'iY2':xiY2," + #EOL +
	                   "          'sY2Mode':'xsY2Mode'," + #EOL +
	                   "          'sGadgetFont':'xsGadgetFont'" + #EOL
	#JSON_LayoutItem_Seperator = "            }," + #EOL
	#JSON_LayoutItem_NextLayout = "        }" + #EOL +
	                              "      }" + #EOL +
	                              "    }," + #EOL
	#JSON_LayoutItem_End = "        }" + #EOL +
	                       "      }" + #EOL +
	                       "    }" + #EOL
	#JSON_Layout_End = "  }" + #EOL +
	                   "}"
Also, ExtractJSONStructure and InsertJSONStructure/ ComposeJSON sort completely different in SpiderBasic and PureBasic.
Actually JSON structures are not sorted at all, but SB and PB usually create a structure in the same way. But SB and PB unfortunately do it exactly the opposite way. So for my x-platform compatible module this was a nogo.

Markus
SB 2.32 x86, Browser: Iron Portable V. 88.0.4500.0 (Chromium based), User age in 2023: 55y
"Happiness is a pet." | "Never run a changing system!"
Post Reply