1、在用HttpService组件获取数据,并将数据转成JSON格式时,经常会抛出类似以下的异常:
JSONParseError: Unexpected u encountered
。解决的办法是:将json数据的key用双引号(用单引号也不行)括起来,比如
将 {username:"uid", password:"pwd"} 改成 {"username":"uid", "password":"pwd"}。
2、在用RemoteObject组件访问Java类的方法时,经常会抛出类似以下的异常:
Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 400:
url: 'http://localhost:8888/WebContent/messagebroker/amf'
这是由于访问amf的路径不正确导致的。这里假定页面的访问路径为:http://localhost:8888/ddd/bin/ddd.html,那么 web context 就是ddd,而访问amf的路径中web context却为WebContent,两者不一致了。所以,必须对访问amf的路径的web context进行修改。
修改办法:右击工程 》Properties 》Flex Server 》修改Context root的值,如图:
3、在用GraniteDS的SecureRemoteObject组件访问destination时,经常会抛出类似以下的异常:
<service id="granite-service" class="flex.messaging.services.RemotingService" messageTypes="flex.messaging.messages.RemotingMessage"> <default-channels> <channel ref="my-graniteamf"/> </default-channels> <destination id="securityService"> <properties> <factory>spring</factory> <source>securityService</source> </properties> </destination> </service>
这是由于mxml文件中引用了名为securityService的destination,所以在编译mxml文件时必须在编译参数中引用包含destination的services-config.xml文件。具体配置方法如下:
在工程的属性窗口中,定位到Flex Compiler子菜单中,在Additional compiler arguments中输入:-services "C:/Documents and Settings/Administrator/桌面/gdstest2/gdstest/WebRoot/WEB-INF/flex/services-config.xml" -locale en_US。services-config.xml文件的实际路径需要作调整。