Android: 休息 api returns 不完整的回应

Android: Rest api returns incomplete response

我正在使用 restful 网络服务,其中 returns 数据从 sql 服务器传输到我的 android 应用程序,如果我得到 100 条记录它工作正常但是如果获取 1,000 条记录我的日志显示不完整和损坏 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;
    }

在您的代码中 "doc list" 日志可能被截断。 "total records" 是一个整数,因此被截断了。

要记录"jsonObj",唯一的方法是将其存储在文件中。 您必须添加写入外部存储的权限:

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

然后将您的对象放入文件中:

 // 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)
    {
    }
}