我正在尝试在我的 Android 项目中创建一个 JSONObject。它似乎有效,但它似乎只记住我最后放入的内容。这段代码:

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);
}

打印出来 {"customer_uuid": "123"}. 。但是当我删除放入 customer_uuid 的行时,它只打印出来 {"text", "thi sis the message"}.

为什么它只记得我最后输入的内容?更重要的是,我如何让它存储这两个东西?欢迎所有提示!

有帮助吗?

解决方案

更改为 Log.wtf("asassa", json.toString());

您的标签可能没有那么长,因此会被截断。请参阅 参考页 更多细节。

其他提示

你的代码没问题,但是你记录错误了。不要使用 标签 对于日志记录(第一个参数),请使用 信息 (第二):

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

还要确保 customer_uuid 变量不是 null, ,除非它不会添加到您的 JSON 中。

jsonObject.toString(2);

人类可读的字符串

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top