I'm a little bit stuck on this one. I'm trying to compare a String against a jsonobject.getString and it seems whatever I do they do not match:
String date = scoreJson.getString("Date");
if (dateString.equals(date))
{
//do stuff
}
The value of dateString is assigned here:
calendar = Calendar.getInstance();
int day = calendar.get(calendar.DAY_OF_MONTH), month = calendar.get(calendar.MONTH), year = calendar.get(calendar.YEAR);
//months start at 0 in calendar
month += 1;
//use builder to create the dateString
builder.append(year).append("-").append(month).append("-").append(day);
dateString = builder.toString();
When I view both Strings in debug they show "2015-05-18", however they will not match in a conditional statement. Does anyone have any idea why, and how I could compare them?
Thanks.
Edit: The JSON object will come back in this format:
{"ScoreData":{"Username":"testUser","Id":"8fb25209-863a-410b-a440-
b5b57a903ee1","Date":"2015-02-25","Score":"25.3"}}
I am retrieving the values from it here and saving to sharedprefs:
//response comes back as two JSONObjects, this makes the inner object into a new JSON
JSONObject responseJson = new JSONObject(response);
JSONObject scoreJson = new JSONObject(responseJson.getString("ScoreData"));
String date = scoreJson.getString("Date");
puzzleScore = scoreJson.getString("Score");
SharedPreferencesWrapper.saveToPrefs(c, "score-" + date, puzzleScore);
I am then checking for the key here:
puzzleScore = SharedPreferencesWrapper.getFromPrefs(c, "score-" + dateString, "NotFound");
if (!puzzleScore.contains("NotFound"))
{
//do stuff
}
code SharedPreferencesWrapper.saveToPrefs(c, "score-" + date, puzzleScore);code puzzleScore = SharedPreferencesWrapper.getFromPrefs(c, "score-" + dateString, "NotFound");