android-在adb logcat输出中格式化json字符串 [英] android - format json string in adb logcat output
本文介绍了android-在adb logcat输出中格式化json字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
出于记录目的,我打印出json响应字符串,并可以在android"adb logcat"命令中看到它们.有没有一种方法可以很好地格式化adb logcat输出中的json字符串,使其看起来像这样?
For logging purpose, I print out json response string and can see them in android "adb logcat" command. Is there a way to nicely format the json string in adb logcat output so that it looks like this?
{ "code" : "0",
"text" : "hello world"
}
推荐答案
You can use the JSONObject.toString()
method to pretty print the JSON on logcat.
Log.d("tag", jsonObject.toString(4));
输出
(29124): {
(29124): "text": "hello world",
(29124): "code": "0"
(29124): }
这篇关于android-在adb logcat输出中格式化json字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文