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