-1

I'm trying to create a JSONObject in my Android project. It seems to work, but it only seems to remember the last thing I put into it. This code:

JSONObject json = new JSONObject();
try {
    json.put("text", "thi sis the message");
    json.put("customer_uuid", customer_uuid);
    Log.wtf(json.toString(), "asassa");
} catch (JSONException e) {
    Log.wtf("WTF", e);
}

Prints out {"customer_uuid": "123"}. But when I erase the line in which the customer_uuid is put in, it only prints out {"text", "thi sis the message"}.

Why does it only remember the last thing I put in? And more importantly, how do I make it store both the things? All tips are welcome!

4

3 回答 3

3

Change to Log.wtf("asassa", json.toString());

Your tag may not be that long so it gets truncated. See the reference page for more details.

于 2013-11-15T15:27:35.033 回答
3

Your code is okay, but you log it wrong. Don't use the tag for logging (first parameter), use the message (second):

Log.wtf("SOME_TAG", json.toString());

Also be sure that the customer_uuid variable is not null, unless it will not be added into your JSON.

于 2013-11-15T15:31:55.403 回答
2

jsonObject.toString(2);

human-readable string

于 2013-11-15T15:34:42.947 回答