Hi all,
When i do this the result is 6 (good)
var inhouddatabase = ['a', 'b', 'c', 'd', 'e', 'f']; var maxVal = inhouddatabase.length; Ti.API.log('database:'+maxVal);but when i do this the result is 44 (wrong) Any clue why this happends?
var inhouddatabases = ['a', 'b', 'c', 'd', 'e', 'f']; Titanium.App.Properties.setString("database",inhouddatabases); var inhouddatabase = Ti.App.Properties.getString('database'); var maxVal = inhouddatabase.length; Ti.API.log('database:'+maxVal);
8 Answers
Accepted Answer
Titanium.App.Properties.setString("database",JSON.stringify(inhouddatabases)); var db = JSON.parse(Titanium.App.Properties.getString("database"));
Well maybe you should use setList as it was intended instead of setString.
Hi Gerd
Use setList instead of setString.
This can take array information, without needing to change it from an array to anything else first, same is true when retrieving it.
now i added an array of data to the var but he gives and error when i try to get it for a count
var inhouddatabase = Ti.App.Properties.getList('database'); var maxVal = inhouddatabase.length; Ti.API.log('database:'+maxVal);the error
[ERROR] { line = 68; message = "'undefined' is not an object (evaluating 'inhouddatabase.length')"; name = TypeError; sourceId = 233238176; sourceURL = "file://localhost/Users/NBhosting/Library/Application%20Support/iPhone%20Simulator/5.1/Applications/08F671E2-697A-4B5E-813C-4039509DA3B3/test.app/functies.js"; }
i filled database with data from php/json i parsed it with var content = JSON.parse(this.responseText); and added the result to database
my returned data from php looks like this
{"0":{"pid":"2","profielnaam":"garett","leeftijd":"22","foto":"1284251614yzyms.jpg"},"1":{"pid":"12","profielnaam":"francois","leeftijd":"24","foto":"Francois23.jpg"},"2":{"pid":"23602","profielnaam":"Robin","leeftijd":"19","foto":"1292933541hdstv.jpg"},"3":{"pid":"23599","profielnaam":"Stef30","leeftijd":"30","foto":""},"4":{"pid":"23087","profielnaam":"unexpected1","leeftijd":"48","foto":""},"5":{"pid":"23587","profielnaam":"rudie58","leeftijd":"53","foto":"1290706787jmnpf.jpg"},"6":{"pid":"23076","profielnaam":"monique","leeftijd":"29","foto":"1282915347rellf.jpg"},"7":{"pid":"24959","profielnaam":"thomaz","leeftijd":"34","foto":""},"8":{"pid":"870","profielnaam":"ixixon","leeftijd":"35","foto":"Ixixon.jpg"},"9":{"pid":"898","profielnaam":"jawsper","leeftijd":"32","foto":"jawsper.jpg"},"10": ***** ***** more ***** ***** {"aantal":5808}}
Hi Gerd
This might be because you swapped the array to an object (this may contain arrays) but not the same.
Try setObject in place of the current setList.
If that fails, validate your JSON using something like jsonlint.com, if that works post your code with the set property in it.
done that , var seems to be an object now [INFO] database:[object Object]
how do i cont with an object?
var inhouddatabase = Ti.App.Properties.getObject('database'); var maxVal = inhouddatabase.length; Ti.API.log('database:'+inhouddatabase); Ti.API.log('database:'+maxVal);returns undifined
tryed to add
datadb:[ datahere ]donest seem to work either
got it working, was missing [] in my output from php
Your Answer
Think you can help? Login to answer this question!