ColdFusion, HowTo Convert String to Array?

Given the following line in ColdFusion:

ul[0][id]=main1 &ul[0][children][0][id]=child2 &ul[0][children][0][class]= &ul[1][id]=main3 &ul[2][id]=main4 &ul[3][id]=main5 

How to create an array with the information above?

thank

+3
source share
3 answers

looking at the string, it seems that what you are trying to do is transform the vertex string into an array of structures. this is what we did in cfwheels in our dispatcher, and it's quite complicated. to see how we do this, look at the dispatcher code:

http://code.google.com/p/cfwheels/source/browse/trunk/wheels/dispatch/request.cfm

The following methods are considered:

$ CreateParams ()

$ getParameterMap ()

$ createNestedParamStruct ()

$ createNewArrayStruct ()

+2

, , - . , , " " (, children), -, (.. children[0], id class, ).

ul                         = [];
ul[1]                      = {}; // ColdFusion arrays are not zero-indexed
ul[1]['id']                = 'main1';
ul[1]['children']          = {}; // Another struct
ul[1]['children']['id']    = 'child2';
ul[1]['children']['class'] = '';  // blank in your example
ul[2]['id']                = 'main3';
ul[3]['id']                = 'main4';

...etc...

, - , . .

: , CFML? serializeJSON() , , deserializeJSON(), .

+1

The cfc form utilities sound the way you need them.

http://formutils.riaforge.org/

0
source

Source: https://habr.com/ru/post/1746312/


All Articles