在 Logcat 上显示更多字符串
我目前正在开发一个 Android 应用程序,它使用“JSON”作为服务器的响应。 通常我处理 JSON 响应。但现在我遇到了 logcat 的问题, 如果 JSON 响应字符串非常长,超过 x 个字符(我不知道 logcat 可以显示的最大字符串到底是多少),则某些 JSON 字符串丢失。
虽然它仍然可以给我输出,但我需要从服务器传输的 JSON 字符串的信息。
是否有可能在 logcat 上显示更多字符串?就像增加缓冲区或任何可以用来增加 logcat 可以显示的最大字符串长度的参数一样。
I am currently working on an android App that uses 'JSON' as response from server.
Usually I work on the JSON response. But now I have a problem with logcat,
if the JSON response string is very long , more than x character (i don't know exactly how much is the max string that could be displayed by logcat), some of the JSON string is missing.
Although it still could give me the output, I need the information on the JSON string that is transmitted from the server.
Is there any possibility to display more string on logcat? Like increasing the buffer or any parameter that I could use to increase the maximum string length that could be displayed by logcat.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
丑陋但它能完成工作:
Ugly but it does the job:
我就是这样做的。
This is how I did it.
我们的一些 RESTful API 返回非常长的 JSON 响应。下面是为 LogCat 设置格式的方法:
Some of our RESTful APIs return very long JSON responses. Here's the method which formats them for LogCat:
如果您没有使用 Eclipse,或者您使用了但 @Nanne 答案对您不起作用,我只能考虑两种选择:
编辑:另一种可能性:将 JSON 像日志一样写入 SD 卡中的文件,然后在要检查响应时检索该文件
if you are not using eclipse, or you are but @Nanne answer doesn't work for you I can only think in two alternatives:
edit: Another possibility: write the JSON to a file in SD card like a log, and then retrieve the file when you want to check the response
为什么不从命令行使用 logcat ?
我怀疑这是否会是你所期待的,但为什么不尝试一下呢?
发出命令
./adb -e logcat
从包含 adb 的目录 。
这是针对模拟器的。
将设备的
-e
替换为-d
why not use logcat from a command line?
I doubt whether it will be what you're expecting, but why not give it a try?
issue the command
./adb -e logcat
from the directory which has adb.
this is for emulator.
replace
-e
with-d
for a device一般来说,如果您想将输出输出到 Logcat 中,您应该使用“Log”命令。
示例:
d = 调试
TAG = 您定义的字符串,显示在 Logcat 中“正常”输出之前的列中
OUTPUT = 你想要打印的东西
有关更多信息:
http://developer.android.com/guide/developing/debug -tasks.html
编辑:
我之前提到的是,为了测试一些你不应该使用的输出:
你应该在代码中使用它:
它会显示在 Logcat 中。我不知道为什么,但这不是更好的方法。
像这样,您还可以显示错误消息:
它将更改 Logcat 中输出的颜色,因此如果发生错误,您可能会更好地看到它。
In general if you want to get output into Logcat you should use the "Log" command.
An example:
d = debug
TAG = a string you define, gets displayed in Logcat in the column before the "normal" output
OUTPUT = stuff u want to get printed
For further information:
http://developer.android.com/guide/developing/debug-tasks.html
EDIT:
What I ment before is, in order to test some things with outputs you shouldn't use:
Instead of using this you should use in your code:
It will get displayed in Logcat. I don't exactly know why, but it't the better way.
Like this you also could display an error message:
It will change the color of your output in Logcat, so you may see it better if e.g. an error occurrs.