Android如何在logcat中查看长字符串 [英] Android how to view long string in logcat

查看:266
本文介绍了Android如何在logcat中查看长字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的HashMap<String, LinkedHashMap<String,String>相当长(不是问题),在使用其中的数据之前,我试图确保一切看起来正确.为此,我试图仅尝试执行Log.v("productsFromDB",products.toString()),但是在LogCat中它显示了大约1/3.有没有办法输出整个地图?

I have a HashMap<String, LinkedHashMap<String,String> that is fairly long (not an issue) and I'm trying to make sure things look correct before I use the data inside it. To do this I'm trying to just attempting to do this Log.v("productsFromDB",products.toString()) but in the LogCat It shows about 1/3 of it. Is there a way to output the entire map?

推荐答案

Logcat只能显示约4000个字符.因此,您需要调用一个递归函数来查看整个哈希图.试试这个功能:

Logcat can only show about 4000 characters. So you need to call a recursive function to see the entire hashmap. Try this function:

public static void longLog(String str) {
    if (str.length() > 4000) {
        Log.d("", str.substring(0, 4000));
        longLog(str.substring(4000));
    } else
        Log.d("", str);
}

这篇关于Android如何在logcat中查看长字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆