0

我有这个从 http web 服务中检索购物车数组的 FlexMobile 项目。如果购物车中没有商品,则返回的 json 为空,从而导致解析错误

这是 JSON 响应:

{ "cart": [ ] }

这是错误:

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()

这是我正在使用的代码。这是我第一次尝试弹性应用程序,所以期待新手方法等......

<?xml version="1.0" encoding="utf-8"?>
<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">
<fx:Script>
    <![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");
        }

    ]]>
</fx:Script>
<fx:Declarations>
    <s:CallResponder id="getCartResult" fault="onFault(event)" />
    <rincomobile:RincoMobile id="rincoMobile" />
    <s:CallResponder id="getCartTotalResult"/>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:List id="list" left="0" right="0" top="0" bottom="176" borderVisible="false"
        creationComplete="list_creationCompleteHandler(event)"
        itemRenderer="renderers.cartRenderer" labelField="item_code">
    <s:AsyncListView list="{TypeUtility.convertToCollection(getCartResult.lastResult.cart)}"/>
</s:List>
<s:Button id="btn_checkout" bottom="93" width="90%" label="${getCartTotalResult.lastResult.cart[0].total}  Checkout" chromeColor="#091A33" horizontalCenter="0"/>
<s:Button bottom="10" width="90%" label="Continue Shopping" chromeColor="#091A33"
          horizontalCenter="0"/>
</s:View>
4

1 回答 1

1

空数组是 Flex JSON 序列化器解码器的一个已知问题。据说它将在 flex4.5 中修复。请参阅以下链接: http ://forums.adobe.com/thread/605070

于 2011-02-27T23:59:10.177 回答