AS3。如何将 php 中的 json 数组保存到 sqlite 中?
AS3. How to save json array from php into sqlite?
我有 JSON 数组 数据来自 Mysql 和 Php ,
我想将这个 JSON 数组 存储在 SQLite 中并像 JSON 数组一样取回它
this the output of the json array it come from the php
{
"task": [
{
"id": "1",
"tid": "100",
"ttitles": "test",
"stime": "2018-10-08 02:40:28",
"seentime": null,
"subject": "Testing",
"ftime": null,
"uid": "1101",
"tsp": "11001"
},
{
"id": "2",
"tid": "101",
"ttitles": "tesst",
"stime": "2018-10-08 02:41:17",
"seentime": null,
"subject": "Tessting",
"ftime": null,
"uid": "1101",
"tsp": "110001"
}
]
}
and this the AS3 code to get the data result from php
public function processTasks():void
{
var request:URLRequest = new URLRequest();
request.url = "http://xxxxxxxxxxxxxxxxxx.xxx/a/tasks.php?
empid="+empid;
request.requestHeaders = [new URLRequestHeader("Content-Type",
"application/json")];
request.method = URLRequestMethod.GET;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, receive);
loader.load(request);
}
public function receive(event:Event):void
{
// here i want get the Json Array data then store in to SQLite
// And get back again as a JSON .
}
i do already change the result come from the PHP from JSON to String_Array with
splitByComma(extrnalString:String) , i save it in SQLite Already and this good for me .
这是适用于我的代码;
public function processTasks():void
{
var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest();
varSend.url = "http://localhost/a/tasks.php?empid="+empid;
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
variables.myrequest = "get_data_array";
varLoader.load(varSend);
function completeHandler(event:Event):void
{
var returnStr:String = event.target.data.returnString;
splitByComma(returnStr);
}
}
public function splitByComma(extrnalString:String):void
{
var myArray:Array = extrnalString.split("(||)");
for(var element:String in myArray){
i++;
var innerArray:Array = myArray[element].split("|");
movie_id = innerArray[0];
movie_taskid = innerArray[1];
movie_tasktitles = innerArray[2];
movie_taskstime = innerArray[3];
movie_taskseentime = innerArray[4];
movie_tasksubject = innerArray[5];
movie_taskftime = innerArray[6];
movie_taskuid = innerArray[7];
movie_tasktsp = innerArray[8];
openDB_to_Insert();
}
我有 JSON 数组 数据来自 Mysql 和 Php , 我想将这个 JSON 数组 存储在 SQLite 中并像 JSON 数组一样取回它
this the output of the json array it come from the php
{
"task": [
{
"id": "1",
"tid": "100",
"ttitles": "test",
"stime": "2018-10-08 02:40:28",
"seentime": null,
"subject": "Testing",
"ftime": null,
"uid": "1101",
"tsp": "11001"
},
{
"id": "2",
"tid": "101",
"ttitles": "tesst",
"stime": "2018-10-08 02:41:17",
"seentime": null,
"subject": "Tessting",
"ftime": null,
"uid": "1101",
"tsp": "110001"
}
]
}
and this the AS3 code to get the data result from php
public function processTasks():void
{
var request:URLRequest = new URLRequest();
request.url = "http://xxxxxxxxxxxxxxxxxx.xxx/a/tasks.php?
empid="+empid;
request.requestHeaders = [new URLRequestHeader("Content-Type",
"application/json")];
request.method = URLRequestMethod.GET;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, receive);
loader.load(request);
}
public function receive(event:Event):void
{
// here i want get the Json Array data then store in to SQLite
// And get back again as a JSON .
}
i do already change the result come from the PHP from JSON to String_Array with splitByComma(extrnalString:String) , i save it in SQLite Already and this good for me .
这是适用于我的代码;
public function processTasks():void
{
var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest();
varSend.url = "http://localhost/a/tasks.php?empid="+empid;
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
variables.myrequest = "get_data_array";
varLoader.load(varSend);
function completeHandler(event:Event):void
{
var returnStr:String = event.target.data.returnString;
splitByComma(returnStr);
}
}
public function splitByComma(extrnalString:String):void
{
var myArray:Array = extrnalString.split("(||)");
for(var element:String in myArray){
i++;
var innerArray:Array = myArray[element].split("|");
movie_id = innerArray[0];
movie_taskid = innerArray[1];
movie_tasktitles = innerArray[2];
movie_taskstime = innerArray[3];
movie_taskseentime = innerArray[4];
movie_tasksubject = innerArray[5];
movie_taskftime = innerArray[6];
movie_taskuid = innerArray[7];
movie_tasktsp = innerArray[8];
openDB_to_Insert();
}