arrays - jQuery wont turn this is into JSON -


so code want turn json following

var locationdata = []; locationdata['lat'] = position.coords.latitude; locationdata['long'] = position.coords.longitude; locationdata['address']['road'] = data['address']['road']; locationdata['address']['suburb'] = data['address']['suburb']; locationdata['address']['city'] = data['address']['city']; locationdata['address']['county'] = data['address']['county']; locationdata['address']['state'] = data['address']['state']; locationdata['address']['postcode'] = data['address']['postcode']; locationdata['address']['country'] = data['address']['country']; locationdata['address']['country_code'] = data['address']['country_code']; 

but when run it, not alert me has been successful

your initial declaration wrong:

var locationdata = []; 

that creates array, not work expect; want object instead. need initialize complex data structure inside, such address:

var locationdata = {     address: {} } 

sidenote

an array object in javascript, behaves in special way when using numeric properties. in case you're not using numeric properties @ all, why regular object suits needs better.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -