title: JavaScript $http.get an json array and store it in localstorage
body: <p>I'm trying to receive an json Array and store it in the local storage. 
  I've seen some questions like this but they couldn't help me. So i wanted to try with my own question. Im developing in Ionic Framework.</p>
  
  <p>My controller includes following:</p>
  
  <pre><code>app.controller('QuestionsCtrl', function($scope, $http, $stateParams, $localstorage) {
  
  $scope.getData = function() {
  
  // get the json
     $http.get("data/fragenArray.json")
          .success(function(data) {
  
          //output of json as a string  -&gt; correct
          console.log('data: ' + JSON.stringify(data));
  
          // store json in local storage
          $localstorage.setObject('fragenset', data);
  
          // restore json from local storage
          var post = $localstorage.getObject('fragenset');
  
          // output of local storage item -&gt; incorrect
          // I got: Test xxx: [object Object]
          console.log('Test xxx: ' + post);
       })
       .error(function(data) {
              alert("ERROR");
          });
      }
   });
  </code></pre>
  
  <p>To store the json I've got:</p>
  
  <pre><code>angular.module('utils', [])
  
   .factory('$localstorage', ['$window', function($window) {
     return {
       set: function(key, value) {
         $window.localStorage[key] = value;
       },
       get: function(key, defaultValue) {
         return $window.localStorage[key] || defaultValue;
       },
       setObject: function(key, value) {
         $window.localStorage[key] = JSON.stringify(value);
       },
       getObject: function(key) {
         return JSON.parse($window.localStorage[key] || '{}');
       }
     }
   }]);
  </code></pre>
  
  <p>So I decided to try it without the http.get request:</p>
  
  <pre><code>app.run(function($localstorage, $http) {
     $localstorage.setObject('post', {"fragen":[
      {
          "id":"1",
          "frage":"Wie ist das Wetter?",
          "antworten": {
              "a_1":"gut",
              "a_2":"schlecht"
          }
      },
      {
          "id":"2",
          "frage":"Wie geht es dir?",
          "antworten": {
              "a_1":"gut",
              "a_2":"schlecht"
          }
      }
   ]});
     var post = $localstorage.getObject('post');
     console.log(post);
   })
  </code></pre>
  
  <p>And the result ist exactly what i expected - an json object.</p>
  
  <p>So how can i store the json array from the http.get correctly?</p>