title: Android - how to add JSON object to sharedPreferences?
body: <p>I would like to append data into existing JSON object and save data as string into shared preferences with following structure. </p>
  
  <pre><code>"results":[
            {
               "lat":"value",
               "lon":"value"
            }, 
            {
               "lat":"value",
               "lon":"value"
  
            }
          ]
  </code></pre>
  
  <p>How can i do it right?</p>
  
  <p>I tried something like this, but without luck. </p>
  
  <pre><code>// get stored JSON object with saved positions
  String jsonDataString = this.getSharedPreferencesStringValue(ctx, "positions", "last_positions");
  
  if (jsonDataString != null) {
      Log.i(AppHelper.APP_LOG_NAMESPACE, "JSON DATA " + jsonDataString);
      JSONObject jsonData = new JSONObject(jsonDataString);
      jsonData.put("lat", lat.toString());
      jsonData.put("lon", lon.toString());
      jsonData.put("city", city);
      jsonData.put("street", street);
      jsonData.put("date", appHelper.getActualDateTime());
      jsonData.put("time", appHelper.getActualDateTime());
      this.setSharedPreferencesStringValue(ctx, "positions", "last_positions", jsonData.toString());
  } else {
      this.setSharedPreferencesStringValue(ctx, "positions", "last_positions","{}");                  
  }
  </code></pre>
  
  <p>Thanks for any advice. </p>