发送JSON从Flash到PHP

发送JSON从Flash到PHP

本文介绍了发送JSON从Flash到PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要发送阵列数据从Flash到PHP 来发送电子邮件。我想这样做,因为我必须更改 PHP 页每次我的网站形式的变化,因为客户的选择。

I'm trying to send array of data from Flash to PHP to sending e-mail. I'd like to do that because I must change the php page everytime my form site changes because of client's choice.

我的回答是,我可以把这样的对象的数组到PHP?

My answer is, can I send an array of objects like this to php?

var message:Array = new Array ();
message.push ({field_name:"Name", value:"John Lennon"});
message.push ({field_name:"e-mail", value:"[email protected]"});
message.push ({field_name:"Message", value:"Hello goodbye"});

所以,PHP应该recive像一个字符串:

so, PHP should recive a string like:

[
    {
        "field_name":"Name",
        "value":"John Lennon"
    },{
        "field_name":"e-mail",
        "value":"[email protected]"
    },{
        "field_name":"Message",
        "value":"Hello goodbye"
    }
]

确实存在着一些tecnique?

does exist some tecnique?

推荐答案

这应该做的工作给你。

import com.adobe.serialization.json.JSON;

import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;

var message:Array = new Array ();
    message.push ({field_name:"Name", value:"John Lennon"});
    message.push ({field_name:"e-mail", value:"[email protected]"});
    message.push ({field_name:"Message", value:"Hello goodbye"});

var vars: URLVariables = new URLVariables();
    vars.data   = JSON.encode(messages);

var req: URLRequest = new URLRequest();
    req.method      = URLRequestMethod.POST;
    req.data        = vars;
    req.url         = "yourdomain.com"

    ldr.addEventListener(Event.COMPLETE, handleServerResponse);
    ldr.load(req);

所有你需要做的是在PHP中使用#json_de code 方法..关于..

all you have to do is use the #json_decode method in php..regards..

这篇关于发送JSON从Flash到PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 20:22