我对 ActionScript (AS3) / JSON 有疑问。对此可能有一个非常简单的答案,所以如果这似乎是一个非常菜鸟的问题,我深表歉意。
我要做的是获取多个文本字符串,将它们放入一个对象中,然后将该对象作为 JSON 字符串发送到服务器。
我的代码中的其他所有内容都可以正常工作,每当我在文本输入框中输入一段文本并发送对象时,该数组都会产生如下所示的空条目:
{"email":null,"last_Name":null,"first_Name":null,"date_of_birth":null,"telephone":null}
但是,如果我替换customer.first_name = inPutfname
为:customer.first_name = " John";
然后数组追溯如下,这就是我想要的:
{"email":null,"last_Name":null,"first_Name":John,"date_of_birth":null,"telephone":null}
那么如何获取多个输入文本字符串并将它们放入对象中,以便数组像上面示例中那样读回,或者理想情况下像这个示例一样:
{"email":randomemail@email.com"last_Name":smith,"first_Name":john,"date_of_birth":27/07/1989,"telephone":012343456788}
这是我到目前为止的代码:
var inPutFirstname: String;
var inPutLastname: String;
var inPutEmail: String;
var inPutTelephone: String;
var inPutDob: String;
// changes customer data into an object
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
var customer:Object = new Object;
customer.first_Name =inPutFirstname;
customer.last_Name = inPutLastname; PROBLEM AREA?
customer.email = inPutEmail;
customer.date_of_birth = inPutDob;
customer.telephone = inPutTelephone;
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//changes customer object into json string
var myJson: String = JSON.stringify(customer);
var myVariableUrl: URLVariables = new URLVariables();
myVariableUrl.data = JSON.stringify(myVariableUrl);
var myRequestUrl: URLRequest = new URLRequest();
var authHeaderUrl: URLRequestHeader = new URLRequestHeader("xxxxxx", "xxxxxxx");
myRequestUrl.method = URLRequestMethod.POST;
myRequestUrl.data = myJson;
myRequestUrl.url = "website url"
var uload: URLLoader = new URLLoader();
uload.load(myRequestUrl);
uload.load(myRequestUrl);
mySendbutton.addEventListener(MouseEvent.MOUSE_DOWN, thefunction1);
// captures text from the input and places them into the customer object
function captureText1(): void {
inPutFirstname = myFirstName.text;
inPutLastname = myLastName.text;
inPutEmail = myEmail.text;
inPutDob = myDob1.text + myDob2.text + myDob3.text;
inPutTelephone = myTele.text;
}
function thefunction1(event: MouseEvent): void {
captureText1();
trace(inPutfname);
trace(myJson);
}
任何帮助都会很棒。
多谢你们