0

i'm using a restful web service which returns data from sql server to my android app, if i get 100 records it works fine but if get 1,000 records my log shows incomplete and broken json.

    @Override
    public ArrayList<CRM_table> doInBackground(Void... params) {

        RestAPI api = new RestAPI();
            RestAPI api = new RestAPI();
        try {
            Log.e( "In background try block","yee"); 
            JSONObject jsonObj = api.GetDoctors(num);
            JSONParser parser = new JSONParser();
            Log.e( "doc list", jsonObj.toString()); 

            //table = parser.parseCrmTable(jsonObj);
                int itemCount = table.size();
            Log.d("total records",Integer.toString(itemCount));


        } catch (Exception e) {
            Log.e( "bg error", e.getMessage()); 

        }
        return table;
    }
Andrain
  • 872
  • 1
  • 16
  • 43
  • Logcat is truncated. See this post: http://stackoverflow.com/questions/8888654/android-set-max-length-of-logcat-messages – LaurentY Feb 13 '15 at 08:09
  • so is there a way to check the length of response. i actually want to know the number of records my service is returning. – Andrain Feb 13 '15 at 08:16

1 Answers1

1

In your code "doc list" log could be truncated. "total records" is an Integer so it's truncated.

To log "jsonObj" the only way is to store it in a file. You have to add permission to write external storage:

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

And then put your object in file:

 // Get the directory for the app's private pictures directory. 
    File file = new File(context.getExternalFilesDir(
            Environment.DIRECTORY_xxxxxx), fileName);
    if (!file.mkdirs()) {
        Log.e(LOG_TAG, "Directory not created");
    }
    BufferedWriter writer = null;
try
{
    writer = new BufferedWriter( new FileWriter( file));
    writer.write( yourstring);

}
catch ( IOException e)
{
}
finally
{
    try
    {
        if ( writer != null)
        writer.close( );
    }
    catch ( IOException e)
    {
    }
}
LaurentY
  • 7,495
  • 3
  • 37
  • 55