Trying to work with a JSON object and need to stringify it for localStorage:
$http.post('http://localhost:8000/refresh', {
name: $scope.name,
email: $scope.email,
token: $rootScope.devToken,
platform: ionic.Platform.platform()
}).then(function(response) {
console.log("Saving profile");
window.localStorage.setItem("UserProfile", JSON.stringify(response.data));
$state.go('home');
});
Retrieving the data from localStorage:
var temp = window.localStorage.getItem("UserProfile");
var profile = JSON.parse(temp);
console.log("Profile: " + profile);
When logging the profile, it shows [Object object]. Need help converting it back into an object.
EDIT: JSON Data:
[
{
userProfileID: 1,
firstName: 'Austin',
lastName: 'Hunter',
email: 'ahunasdfgk.com',
token: '',
platform: '',
password: 'inc3',
companyProfileID: 1,
authentication: '',
UserTopics: [...]
}
The current log of profile displays a complex structure. Help needed in parsing the JSON correctly.