ActionScript 3错误无效的JSON解析输入

I'm trying to send data to a PHP file via JSON but i'm getting an error when trying to JSON the data.

I'm pretty sure i'm doing this right. Any suggestions ?

Here's my ActionScript 3 code :

var dataToSend:Array = new Array();

var data:Object = new Object(); 
    data.callFunction = "getQuestion";  
    data.numberOfQuestions = "1";   

dataToSend.push(data);

trace(data);

var variables:URLVariables = new URLVariables();    
    variables.data = JSON.stringify(dataToSend);

var url:String = "myurl";

var request:URLRequest = new URLRequest(url);   
    request.method = URLRequestMethod.POST; 
    request.data = variables;    

var loader:URLLoader = new URLLoader(); 
    loader.load(request);   
    loader.addEventListener(Event.COMPLETE, requestComplete);

And my PHP code :

if $data[ "callfunction" ] = "getQuestion";
{
    echo("Sent");
}

Your ActionScript 3 code looks fine but you have some problems in your PHP's one.

Let's see that.

    1. The if statement in PHP is like the AS3's one :
&lt?php
    if( condition )
        instruction;
?&gt
    1. The equality operator is the == and not the assignment one ( = ).
    1. As you have sent your data using the POST method, you can use the PHP's $_POST array to get it.
    1. Then, as you have sent it on JSON format, you can decode it using the decode_json() function in your PHP side.

So your PHP code can be like this for example :

<?php

    if(isset($_POST['data']))
    {
        $data = $_POST['data'];
        $json_data = json_decode($data);        

        if($json_data[0]->callFunction == "getQuestion")
        {
            echo("Sent");
        }
    }

?>

Then you can get the response of your PHP script in your AS3 requestComplete function :

function requestComplete(e:Event): void 
{
    trace(URLLoader(e.target).data);    // gives : Sent, for example
}

...

Hope that can help.