Send Complex Object FROM Flex to PHP

I want to be able to send complex data from Flex to PHP and be able to parse that data via PHP script. I'm able to send a basic key value pair object but anything more complex than that doesn't translate accordingly.

This works...

ht.send({label:"FOO", label2:"FAA", label3:"FII", label4:"FEE"});

It translates as expected

This doesn't work...

ht.send({obj11:{label:"FOO", label2:"FAA"}, obj2:{label3:"FII", label4:"FEE"}});

It is posted as a string [object][object].

Is it possible to send complex data to PHP? I've tried JSON.encode(object). Do I need to send XML instead?


I believe Json didn't work because you didn't set it up correctly

var myComplexObject:Object ={obj11:{label:"FOO", label2:"FAA"}, obj2:{label3:"FII", label4:"FEE"}}

var dataToSend:Object = { data: JSON.encode(myComplexObject) }


// on the php side you will have something like so

$data = json_decode(  $_POST['data'] );

echo '<pre>';
print_r( $data );

I would highly recommend using AMF instead of JSON, given it's native support in Flex.

If you are working with large datasets, I have found AMF more effective, but at the end of the day it boils down to what you're most comfortable with. AMF will be easier to work with in Flex, though.

Interesting reads:

Need Your Help

Visual studio 2012 ASP.NET webadminfiles error

c# visual-studio-2012

Hi so I am trying to create a login form for my website but when I open the ASP.NET configuration it gives me an error.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.