Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android - format json string in adb logcat output

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" }  
like image 785
Michael Avatar asked Apr 07 '13 18:04

Michael


1 Answers

You can use the JSONObject.toString() method to pretty print the JSON on logcat.

Log.d("tag", jsonObject.toString(4)); 

Output

(29124): { (29124):     "text": "hello world", (29124):     "code": "0" (29124): } 
like image 50
Deepak Bala Avatar answered Sep 20 '22 14:09

Deepak Bala