Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 984451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:01:02+00:00 2026-05-16T05:01:02+00:00

In order to send a POST request I need to enumerate all properties of

  • 0

In order to send a POST request I need to enumerate all properties of a given object. This object may or may not be dynamic. I’m looking for the most elegant solution. This is what I’ve got so far:

    function createURLVariables(params:Object):URLVariables
    {
        // Workaround: Flash Player performs a GET if no params are passed
        params ||= {forcePost: true};
        var vars:URLVariables = new URLVariables();
        var propertyName:String;
        var propertyList:XMLList = describeType(params)..variable;
        var propertyListLength:int = propertyList.length();
        // A dynamic object won't return properties in this fashion
        if (propertyListLength > 0)
        {
            for (var i:int; i < propertyListLength; i++)
            {
                propertyName = propertyList[i].@name;
                vars[propertyName] = params[propertyName];
            }
        }
        else
        {
            for (propertyName in params)
                vars[propertyName] = params[propertyName];
        }
        return vars;
    }

One potential problem is that this won’t return properties for getters (accessors).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:01:03+00:00Added an answer on May 16, 2026 at 5:01 am

    I took the following approach in the as3corelib JSON Encoder. You’ll have to modify this to suit your needs, but it should give you an idea to work from. Note that there is some recursion in here (the convertToString call, which you might not need:

    /**
     * Converts an object to it's JSON string equivalent
     *
     * @param o The object to convert
     * @return The JSON string representation of <code>o</code>
     */
    private function objectToString( o:Object ):String
    {
        // create a string to store the object's jsonstring value
        var s:String = "";
        // determine if o is a class instance or a plain object
        var classInfo:XML = describeType( o );
        if ( classInfo.@name.toString() == "Object" )
        {
            // the value of o[key] in the loop below - store this 
            // as a variable so we don't have to keep looking up o[key]
            // when testing for valid values to convert
            var value:Object;
    
            // loop over the keys in the object and add their converted
            // values to the string
            for ( var key:String in o )
            {
                // assign value to a variable for quick lookup
                value = o[key];
    
                // don't add function's to the JSON string
                if ( value is Function )
                {
                    // skip this key and try another
                    continue;
                }
    
                // when the length is 0 we're adding the first item so
                // no comma is necessary
                if ( s.length > 0 ) {
                    // we've already added an item, so add the comma separator
                    s += ","
                }
    
                s += escapeString( key ) + ":" + convertToString( value );
            }
        }
        else // o is a class instance
        {
            // Loop over all of the variables and accessors in the class and 
            // serialize them along with their values.
            for each ( var v:XML in classInfo..*.( 
                name() == "variable"
                ||
                ( 
                    name() == "accessor"
                    // Issue #116 - Make sure accessors are readable
                    && attribute( "access" ).charAt( 0 ) == "r" ) 
                ) )
            {
                // Issue #110 - If [Transient] metadata exists, then we should skip
                if ( v.metadata && v.metadata.( @name == "Transient" ).length() > 0 )
                {
                    continue;
                }
    
                // When the length is 0 we're adding the first item so
                // no comma is necessary
                if ( s.length > 0 ) {
                    // We've already added an item, so add the comma separator
                    s += ","
                }
    
                s += escapeString( v.@name.toString() ) + ":" 
                        + convertToString( o[ v.@name ] );
            }
    
        }
    
        return "{" + s + "}";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this ajax call at the moment: $.ajax({ url: misc/sendPM.php, type: POST, data:
This question is similar to another one, concerning pyCURL I have the following error
is it possible in rails 2.3.X to start a new chain of commands after
There is a nice XSRF protection for link_to method in Rails 3 that generates
I'm developing a RESTful web service with WCF and C#. The service works fine,
I have a Java REST webservice deployed on tomcat (http://localhost:8080/myrestfulapp/aservice/). In my qooxdoo app,
I am processing a csv file to import each rows in a Database. For
I am trying to write a simple console app that POSTs to a page
I'm doing a proof of concept thing here and having a bit more trouble
Consider the (highly simplified) following case: class Dispatcher { public: receive() {/*implementation*/}; // callback

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.