This is fairly simple question but as I'm not using parse.com Android built-in SDK, I got stuck.
I'm trying to pass the data through the following in Android to parse.com even though the object is created with no data, it doesn't work when I include data.
The text box in Android app covnerts the data through this to JSON:
protected JSONObject getBodyTextAsJSON() {
String bodyText = getBodyText();
if (bodyText != null && !TextUtils.isEmpty(bodyText)) {
try {
return new JSONObject(bodyText);
} catch (JSONException e) {
Log.e(LOG_TAG, "User's data is not a valid JSON object", e);
}
}
return null;
}
when I enter some data my Logcat shows the following which seems fine to me:
The code to show log output:
try {
Iterator keys = body.keys();
Log.d(LOG_TAG, "JSON data:");
while (keys.hasNext()) {
String key = (String) keys.next();
Log.d(LOG_TAG, " " + key + ": " + body.get(key));
params.put(key, body.get(key).toString());
}
} catch (JSONException e) {
Log.w(LOG_TAG, "Unable to retrieve a JSON value", e);
}
Say when I enter this data similar to this {"a"="test1", "b"= test2"} in the text body I get the folowing in the logcat:
12-31 09:09:22.631 1991-1991/com.loopj.android.http.sample D/JsonStreamSample: JSON data:
12-31 09:09:22.631 1991-1991/com.loopj.android.http.sample D/JsonStreamSample: a: asd
12-31 09:09:22.632 1991-1991/com.loopj.android.http.sample D/JsonStreamSample: b: ert"
which seems to be fine; however, parse.com does not record the data entered. Instead when the text box is blank it creates the object fine (but with no data which is not desired). It seems to me the JSON in Android and parse.com don't have the same format.