Jump to content

problème lecture JSON


Recommended Posts

Bonjour, j'ai un soucis lorsque j'essai de lire un flux JSON. Le flux est très long (environ 80000 lignes), est cela provoque un OutOfMemory

Cela arrive lorsque je converti la réponse du serveur en String à la ligne :

sb.append(line+NL);

public static String responseReader(InputStream is) {

       String result;
       BufferedReader br = null;

       try {
           br = new BufferedReader(new InputStreamReader(is));
           StringBuilder sb = new StringBuilder();
           String line = "";
           String NL = System.getProperty("line.separator");
           while ((line = br.readLine()) != null) {
               sb.append(line+NL);
           }
           br.close();
           result = sb.toString();

       } catch (IllegalStateException e) {
           Log.e("DEBUGTAG", "Error occured", e);
           return e.toString();
       } catch (Exception e) {
           Log.e("DEBUGTAG", "Error occured", e);
           return e.toString();
       } finally {
           if (br != null) {
               try {
                   br.close();
               } catch (IOException e) {
                   return e.toString();
               }
           }
       }
       return result;
   }

le message d'erreur :


05-26 07:33:28.826: ERROR/AndroidRuntime(288): Uncaught handler: thread main exiting due to uncaught exception
05-26 07:33:28.877: ERROR/AndroidRuntime(288): java.lang.OutOfMemoryError
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:97)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:155)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at java.lang.StringBuilder.append(StringBuilder.java:216)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at com.android.booztermobile.utils.ServletUtils.responseReader(ServletUtils.java:93)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at com.android.booztermobile.servletcall.BlockLoaderCall.BlockLoader(BlockLoaderCall.java:75)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at com.android.booztermobile.activity.ExplorerActivity.generateList(ExplorerActivity.java:530)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at com.android.booztermobile.activity.ExplorerActivity.onClick(ExplorerActivity.java:351)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at android.view.View.performClick(View.java:2364)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at android.view.View.onTouchEvent(View.java:4179)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at android.view.View.dispatchTouchEvent(View.java:3709)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:852)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at android.os.Looper.loop(Looper.java:123)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at android.app.ActivityThread.main(ActivityThread.java:4363)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at java.lang.reflect.Method.invokeNative(Native Method)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at java.lang.reflect.Method.invoke(Method.java:521)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-26 07:33:28.877: ERROR/AndroidRuntime(288):     at dalvik.system.NativeStart.main(Native Method)


J'ai essayé plusieurs façon de faire mais je me retrouve toujours avec ce message...

Link to comment
Share on other sites

  • 2 weeks later...

t'es sur un téléphone ...

c'est pas fait pour parser un JSON de 80000 lignes

il n'y a pas assez de mémoire

plusieurs solutions selon moi :

- tu fais en sorte que le serveur envoie un json plus petit (ne me dit pas que ce n'est pas possible : C'EST POSSIBLE !)

- tu enregistres le json reçu dans un fichier sur la carte sd, et tu le parse "à la main" GL & HF

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...