AS3。如何将JSON数组从PHP保存到sqlite?

时间:2018-10-14 00:21:09

标签: php json actionscript-3

我有 JSON数组数据来自 Mysql和Php , 我想将此 JSON数组存储在 SQLite 中,并像 JSON数组

一样取回它
  

这是来自php的json数组的输出

{
"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"
    }
]
}
  

这是从PHP获取数据结果的AS3代码

        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 .
    }

1 个答案:

答案 0 :(得分:1)

  

我确实已经将来自PHP的结果从JSON更改为String_Array    splitByComma(extrnalString:String),我已经将其保存在SQLite中,这对我有好处。

这是与我一起工作的代码;

    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();
            }