Coldfusion: passing a struct as String through url

后端 未结 2 887
半阙折子戏
半阙折子戏 2021-01-13 08:17

Is there a simple way to serialize a single-level structure as a string for use in a url?

for example:

?key1=val1&key2=val2
2条回答
  •  梦毁少年i
    2021-01-13 08:35

    
    // create simple struct
    x = { a=1, b=2, c=3 };
    WriteDump(x);
    
    // serialize in JSON format and encode for URL transport
    y = URLEncodedFormat( SerializeJSON(x));
    WriteOutput( 'url: #SCRIPT_NAME#?#y#');
    
    // now receive the URL variable and dump it
    if ( StructKeyExists( url, 'z' )) {
        writeOutput( '

    URL Data:

    ' ); writeDump( DeserializeJSON( URLDecode( z))); }

提交回复
热议问题