Note that there are some explanatory texts on larger screens.

plurals
  1. POCapturing and handling json parse errors in FlexMobile Project using web services
    primarykey
    data
    text
    <p>I have this FlexMobile Project that retrieves a cart array from a http web service. If the cart has no items in it, the json returned is empty, thus causing a parse error</p> <p>Here is the JSON response:</p> <pre><code>{ "cart": [ ] } </code></pre> <p>Here is the error:</p> <pre><code>Error: Error while Parsing at com.adobe.serializers.json::JSONDecoder/parseValue()[C:\opt\sb\ide_trunk\ide_builder\com.adobe.flexbuilder.dcrad\serializers\src\com\adobe\serializers\json\JSONDecoder.as:249] at com.adobe.serializers.json::JSONDecoder/parseArray()[C:\opt\sb\ide_trunk\ide_builder\com.adobe.flexbuilder.dcrad\serializers\src\com\adobe\serializers\json\JSONDecoder.as:431] at com.adobe.serializers.json::JSONDecoder/parseValue()[C:\opt\sb\ide_trunk\ide_builder\com.adobe.flexbuilder.dcrad\serializers\src\com\adobe\serializers\json\JSONDecoder.as:222] at com.adobe.serializers.json::JSONDecoder/parseObject()[C:\opt\sb\ide_trunk\ide_builder\com.adobe.flexbuilder.dcrad\serializers\src\com\adobe\serializers\json\JSONDecoder.as:339] at com.adobe.serializers.json::JSONDecoder/parseValue()[C:\opt\sb\ide_trunk\ide_builder\com.adobe.flexbuilder.dcrad\serializers\src\com\adobe\serializers\json\JSONDecoder.as:217] at com.adobe.serializers.json::JSONDecoder/decode()[C:\opt\sb\ide_trunk\ide_builder\com.adobe.flexbuilder.dcrad\serializers\src\com\adobe\serializers\json\JSONDecoder.as:178] at com.adobe.serializers.json::JSONSerializationFilter/deserializeResult()[C:\opt\sb\ide_trunk\ide_builder\com.adobe.flexbuilder.dcrad\serializers\src\com\adobe\serializers\json\JSONSerializationFilter.as:78] at mx.rpc.http::AbstractOperation/http://www.adobe.com/2006/flex/mx/internal::processResult()[E:\dev\hero_private_beta\frameworks\projects\rpc\src\mx\rpc\http\AbstractOperation.as:967] at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\hero_private_beta\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:313] at mx.rpc::Responder/result()[E:\dev\hero_private_beta\frameworks\projects\rpc\src\mx\rpc\Responder.as:56] at mx.rpc::AsyncRequest/acknowledge()[E:\dev\hero_private_beta\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:84] at DirectHTTPMessageResponder/completeHandler()[E:\dev\hero_private_beta\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:451] at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at flash.net::URLLoader/onComplete() </code></pre> <p>Here is the code I am using. This is my first attempt at a flex application, so expect newbie methods etc...</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;s:View xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:rincomobile="services.rincomobile.*" title="view_cart"&gt; &lt;fx:Script&gt; &lt;![CDATA[ import com.adobe.serializers.utility.TypeUtility; import mx.events.FlexEvent; import mx.rpc.events.FaultEvent; private function onFault( event : FaultEvent ) : void { trace(event.fault.message.toString()); } protected function list_creationCompleteHandler(event:FlexEvent):void { getCartResult.token = rincoMobile.getCart("getCart"); getCartTotalResult.token = rincoMobile.getCartTotal("getCartTotal"); } protected function getCartTotal(fuseaction:String):void { getCartTotalResult.token = rincoMobile.getCartTotal(fuseaction); } protected function getCartResult_faultHandler(event:FaultEvent):void { // TODO Auto-generated method stub trace("something happened"); } ]]&gt; &lt;/fx:Script&gt; &lt;fx:Declarations&gt; &lt;s:CallResponder id="getCartResult" fault="onFault(event)" /&gt; &lt;rincomobile:RincoMobile id="rincoMobile" /&gt; &lt;s:CallResponder id="getCartTotalResult"/&gt; &lt;!-- Place non-visual elements (e.g., services, value objects) here --&gt; &lt;/fx:Declarations&gt; &lt;s:List id="list" left="0" right="0" top="0" bottom="176" borderVisible="false" creationComplete="list_creationCompleteHandler(event)" itemRenderer="renderers.cartRenderer" labelField="item_code"&gt; &lt;s:AsyncListView list="{TypeUtility.convertToCollection(getCartResult.lastResult.cart)}"/&gt; &lt;/s:List&gt; &lt;s:Button id="btn_checkout" bottom="93" width="90%" label="${getCartTotalResult.lastResult.cart[0].total} Checkout" chromeColor="#091A33" horizontalCenter="0"/&gt; &lt;s:Button bottom="10" width="90%" label="Continue Shopping" chromeColor="#091A33" horizontalCenter="0"/&gt; &lt;/s:View&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload