Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Very Long String Eclipse Android

I started Android Programming few days ago and make a simple application using JSON request. I have some problems to print to the output console the content of a string. Indeed, the JSON response is quite big (.length() return 93k ) and when I print it with System.out.println, there is only 4013 printed char. How can I retrieve the whole string ? (Or write it to a log file) ?

like image 680
ex0ns Avatar asked Dec 09 '12 20:12

ex0ns


2 Answers

You can use recursion, for example

private void longMsg(String msg) {
    if (msg.length() > 4000) {
        System.out.println(msg); // or whatever you want
        longMsg(msg.substring(4000));
    } else {
        System.out.println(msg); // or whatever you want
    }
}
like image 79
maszter Avatar answered Oct 15 '22 21:10

maszter


May be it will be better for you to output it on device screen? As TextView element.

Or write it in file, using solution like this.

Do not forget to add permission for that in AndroidManifest.xml

<uses-permission 
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        />

For future, to parse JSON use classes from org.json package, they are very easy and helpful.

like image 35
Artem Zinnatullin Avatar answered Oct 15 '22 21:10

Artem Zinnatullin