我正在构建一个flex移动项目。一个视图将配置值发送到服务器。我想通过JSON发送值。我如何循环通过spark表单来填充数组并将数组作为JSON对象发送到服务器?
<fx:Script>
private function sendJSON(event:Event):void
{
var message:Array = new Array();
message.push ({value:blinkGroup.selectedValue,field_name:"blink"});
message.push ({value:macAddress.text,field_name:"macAddress"});
var vars: URLVariables = new URLVariables();
vars.data = JSON.stringify(message);
var req: URLRequest = new URLRequest();
req.method = URLRequestMethod.POST;
req.data = vars;
req.url = "http://server.com/processJSON.php"
var ldr:URLLoader = new URLLoader();
ldr.addEventListener(Event.COMPLETE, handleServerResponse,false, 0, true);
ldr.load(req);
}
</fx:Script>
<fx:Declarations>
<s:RadioButtonGroup id="blinkGroup" enabled="true"/>
</fx:Declarations>
<s:Scroller width="100%" height="100%" verticalScrollPolicy="on" horizontalScrollPolicy="off" x="355" y="10">
<s:Group>
<s:Form id="configureForm" backgroundColor="#DCDCDC">
<s:FormItem backgroundColor="#DCDCDC">
<s:layout>
<s:HorizontalLayout />
</s:layout>
<s:RadioButton groupName="blinkGroup" label="Blink" value="true"/>
<s:RadioButton groupName="blinkGroup" label="No Blink" value="false"/>
</s:FormItem>
<s:FormItem label="MAC Address" backgroundColor="#DCDCDC">
<s:TextInput id="macAddress" text="{getMacAddress()}"/>
</s:FormItem>
<s:FormItem backgroundColor="#DCDCDC">
<s:layout>
<s:HorizontalLayout />
</s:layout>
<s:Button label="OK" click="sendJSON(event)"/>
<s:Button label="Close" click="dispatchEvent(new Event('close'))"/>
</s:FormItem>
</s:Form>
</s:Group>
答案 0 :(得分:0)
我会创建一个Settings类,其中包含设置字段,然后您可以使用JSON.stringyfy(设置)将其作为JSON来执行使用JSON.parse的反转(这会返回一个通用的对象,您可以用于创建一个Settings对象)