Tuesday, December 22, 2009

Flex HTTPService Error 1090 when parsing JSON encoded string

Scenario: Flex/AS3's HTTPService component executes PHP code that generates a JSON array (encoded using json_encode) - the code threw the following error:

  
Main Thread (Suspended: [RPC Fault faultString="Error #1090: XML parser failure: element is malformed." faultCode="Client.CouldNotDecode" faultDetail="null"])   
    mx.rpc.http.mxml::HTTPService/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent   
    mx.rpc.http::HTTPService/http://www.adobe.com/2006/flex/mx/internal::processResult   
    mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler   
    mx.rpc::Responder/result   
    mx.rpc::AsyncRequest/acknowledge   
    DirectHTTPMessageResponder/completeHandler   
    flash.events::EventDispatcher/dispatchEventFunction [no source]   
    flash.events::EventDispatcher/dispatchEvent [no source]   
    flash.net::URLLoader/onComplete [no source]   




 This was working perfectly fine till one array element was generated that contained a Unicode character. The string was: "knowing \u2026 how long"

Solution: Make sure method=GET and resultFormat=text
             url="http://localhost/gen_json.php"
                useProxy="false"
                method="GET"

                resultFormat="text"
                result="OnResult()"/>

No comments:

Followers