2

I'm getting a weird error when using Ti.App.Properties.setList() method.

Here you can see that i have some values. Console:

[INFO] :   id==2251378
[INFO] :   category==[object Object]
[INFO] :   localteam.id==18650
[INFO] :   visitorteam.id==7636
[INFO] :   j==1
[INFO] :   i==2

Now i getlist(); and save in a variable, and in second line create an object and initialize it. And assign some values in it. My Code is:

var myMatchesFootball = Ti.App.Properties.getList('myMatchesFootball');
myMatchesFootballObject = new Object();

myMatchesFootballObject.matchId = "";
myMatchesFootballObject.data    = "";
myMatchesFootballObject.local   = "";
myMatchesFootballObject.visitor = "";
myMatchesFootballObject.index_j = "";
myMatchesFootballObject.index_i = "";


myMatchesFootballObject.matchId = json2.scores.category[e.source.star_indexi].matches.match.id;
myMatchesFootballObject.data    = json2.scores.category[e.source.star_indexi];
myMatchesFootballObject.local   = json2.scores.category[e.source.star_indexi].matches.match.localteam.id;
myMatchesFootballObject.visitor = json2.scores.category[e.source.star_indexi].matches.match.visitorteam.id;
myMatchesFootballObject.index_j = e.source.star_indexj;
myMatchesFootballObject.index_i = e.source.star_indexi;
myMatchesFootballObject.selectedDay  = "myMatches";

myMatchesFootball.push(myMatchesFootballObject);
Ti.App.Properties.setList('myMatchesFootball', myMatchesFootball);

But my app crash and show this error in console,

The Error is: 
[ERROR] :  Script Error {
[ERROR] :      column = 62;
[ERROR] :      line = 888;
[ERROR] :      message = "Attempt to insert non-property list object (\n        {\n        data =         {\n            \"file_group\" = brazil;\n            gid = 1139;\n            id = 1139;\n            matches =             {\n                date = \"Jan 11\";\n                \"formatted_date\" = \"11.01.2017\";\n                match =                 (\n                                        {\n                        \"commentary_available\" = \"\";\n                        date = \"Jan 11\";\n                        events = \"<null>\";\n                        \"fix_id\" = 2042614;\n                        \"formatted_date\" = \"11.01.2017\";\n                        ht =                         {\n                            score = \"\";\n                        };\n                        id = 2251377;\n                        localteam =                         {\n                            goals = \"?\";\n                            id = 7139;\n                            name = \"Cajazeirense de Desportos\";\n                        };\n                        \"static_id\" = 2159519;\n                        status = \"23:30\";\n                        time = \"23:30\";\n                        timer = \"\";\n                        v = 0;\n                        venue = \"\";\n                        visitorteam =                         {\n                            goals = \"?\";\n                            id = 17805;\n                            name = \"Botafogo PB\";\n                        };\n                    },\n                                        {\n                        \"commentary_available\" = \"\";\n                        date = \"Jan 11\";\n                        events = \"<null>\";\n                        \"fix_id\" = 2042611;\n                        \"formatted_date\" = \"11.01.2017\";\n                        ht =                         {\n                            score = \"\";\n                        };\n                        id = 2251378;\n                        localteam =                         {\n                            goals = \"?\";\n                            id = 18650;\n                            name = CSP;\n                        };\n                        \"static_id\" = 2159516;\n                        status = \"23:30\";\n                        time = \"23:30\";\n                        timer = \"\";\n                        v = 0;\n                        venue = \"\";\n                        visitorteam =                         {\n                            goals = \"?\";\n                            id = 7636;\n                            name = \"Treze PB\";\n                        };\n                    },\n                                        {\n                        \"commentary_available\" = \"\";\n                        date = \"Jan 11\";\n                        events = \"<null>\";\n                        \"fix_id\" = 2042610;\n                        \"formatted_date\" = \"11.01.2017\";\n                        ht =                         {\n                            score = \"\";\n                        };\n                        id = 2251379;\n                        localteam =                         {\n                            goals = \"?\";\n                            id = 7366;\n                            name = \"Internacional PB\";\n                        };\n                        \"static_id\" = 2159515;\n                        status = \"23:30\";\n                        time = \"23:30\";\n                        timer = \"\";\n                        v = 0;\n                        venue = \"\";\n                        visitorteam =                         {\n                            goals = \"?\";\n                            id = 20327;\n                            name = Paraiba;\n                        };\n                    },\n                                        {\n                        \"commentary_available\" = \"\";\n                        date = \"Jan 11\";\n                        events = \"<null>\";\n                        \"fix_id\" = 2042612;\n                        \"formatted_date\" = \"11.01.2017\";\n                        ht =                         {\n                            score = \"\";\n                        };\n                        id = 2251380;\n                        localteam =                         {\n                            goals = \"?\";\n                            id = 27182;\n                            name = \"Serrano PB\";\n                        };\n                        \"static_id\" = 2159517;\n                        status = \"23:30\";\n                        time = \"23:30\";\n                        timer = \"\";\n                        v = 0;\n                        venue = \"\";\n                        visitorteam =                         {\n                            goals = \"?\";\n                            id = 7150;\n                            name = \"Auto Esporte\";\n                        };\n                    },\n                                        {\n                        \"commentary_available\" = \"\";\n                        date = \"Jan 11\";\n                        events = \"<null>\";\n                        \"fix_id\" = 2042613;\n                        \"formatted_date\" = \"11.01.2017\";\n                        ht =                         {\n                            score = \"\";\n                        };\n                        id = 2251381;\n                        localteam =                         {\n                            goals = \"?\";\n                            id = 7619;\n                            name = \"Sousa EC\";\n                        };\n                        \"static_id\" = 2159518;\n                        status = \"23:30\";\n                        time = \"23:30\";\n                        timer = \"\";\n                        v = 0;\n                        venue = \"\";\n                        visitorteam =                         {\n                            goals = \"?\";\n                            id = 7195;\n                            name = Campinense;\n                        };\n                    }\n                );\n            };\n            name = \"Brazil: Campeonato Paraibano\";\n        };\n        date = \"11.01.2017\";\n        \"index_i\" = 2;\n        \"index_j\" = 1;\n        local = 18650;\n        matchId = 2251378;\n        name = \"Brazil: Campeonato Paraibano\";\n        selectedDay = myMatches;\n        time = \"23:30\";\n        visitor = 7636;\n    }\n) for key myMatchesFootball";
[ERROR] :      sourceURL = "file:///Users/Apple/Library/Developer/CoreSimulator/Devices/1C82A7E8-F480-4FE1-A0F2-C6F713774B0D/data/Containers/Bundle/Application/500CCBD6-B81D-4D6A-AB8E-0C8E24E379D8/Tipping%20Hub.app/alloy/controllers/football_window_detail.js";
[ERROR] :      stack = "[native code]\nfile:///Users/Apple/Library/Developer/CoreSimulator/Devices/1C82A7E8-F480-4FE1-A0F2-C6F713774B0D/data/Containers/Bundle/Application/500CCBD6-B81D-4D6A-AB8E-0C8E24E379D8/Tipping%20Hub.app/alloy/controllers/football_window_detail.js:888:62";
[ERROR] :  }

But when i comment this line it working fine,

myMatchesFootballObject.data    = json2.scores.category[e.source.star_indexi];

I am also try this but not working,

myMatchesFootballObject.data    = new Object;
Abubakar
  • 21
  • 3

1 Answers1

1

The reason why you are having this error is because you are trying to save nested objects and the setList/getList API does not support it, therefore you get the error Attempt to insert non-property list object

The solution for that is to stringify that object and store it, but, I would not recommend that as a best practice. You should probably use a database using Alloy models instead of saving this in the Ti.App.Properties

A few things that you can change in your code to improve it:

Default the variable to an empty array.

var myMatchesFootball = Ti.App.Properties.getList('myMatchesFootball', []);

Instead of calling new Object, just declare the object and assign the values right to it. (Don't forget the var at the beginning)

var myMatchesFootballObject = {
    matchId: json2.scores.category[e.source.star_indexi].matches.match.id, 
    data: JSON.stringify(json2.scores.category[e.source.star_indexi]),
    // Add other values
};

The rest is ok:

myMatchesFootball.push(myMatchesFootballObject);
Ti.App.Properties.setList('myMatchesFootball', myMatchesFootball);
Cesar Cavazos
  • 271
  • 2
  • 9
  • Thank you, as you mention i am already done this task to stringify my JSON object. And i don't have experience on local database that's why i am not using database. And Thanks for improving my code. let me try. – Abubakar Jan 24 '17 at 10:58
  • No problem. If you find the answer as correct don't forget to mark it for others to use it. It may be a good idea for you to start with Alloy models - you can follow this link http://docs.appcelerator.com/platform/latest/#!/guide/Alloy_Models to get started. Using the Ti.App.Properties to store a lot of information will cause eventually slowness in the app. – Cesar Cavazos Jan 24 '17 at 18:19