0

What's the simplest way to take an object of variable structure and convert it into a URL?

I'm looking for the Apex equivalent of jQuery.param(array) in JavaScript or http_build_query() in PHP.

Here's an example query object:

Map<String, Object> productQueryParams = new Map<String, Object>{
        'q'=>new Map<String,Object>{
                'category'=>'shoes',
                'colors'=> new List<String>{'blue','purple'}
         };
}

And the function I'm looking for would convert this to:

?q[category]=shoes&q[colors][]=blue&q[colors][]=purple

I know how to do this assuming the Map is single level or it's a known structure, but I'd like to do it with parameters of variable structure with multiple levels if possible.

  • What's your specific use case? Are you trying to send it between pages, or between servers/services? – sfdcfox Jul 22 '16 at 21:29
  • between servers – Sabrina Gelbart Jul 23 '16 at 3:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.