2016-09-19 71 views
1

的端予具有包含JSON文件壓縮的​​flie和一些BASE64解碼圖像,我使用下面的代碼來從它讀出的數據:的Android ZipInputStream ZipEntry的不讀取到文件

JSONArray model = new JSONArray(); 
    ZipInputStream zis = new ZipInputStream(new BufferedInputStream(inputStream)); 
    ZipEntry zipEntry; 
    while ((zipEntry = zis.getNextEntry()) != null) { 
     if (zipEntry.getName().equals("model.json")) { 
      long size = (int) zipEntry.getSize(); 
      if (size < 0) { 
       size = 0xffffffffl + size; 
      } 
      byte[] buffer = new byte[(int) size]; 
      int read; 
      while ((read = zis.read(buffer, 0, (int) size)) > 0) { 
       Log.i("model", new String(buffer, "UTF-8")); 
       model = new JSONArray(new String(buffer, "UTF-8")); 
      } 
     } else { 
      long size = (int) zipEntry.getSize(); 
      if (size < 0) { 
       size = 0xffffffffl + size; 
      } 
      byte[] buffer = new byte[(int) size]; 
      int read; 
      while ((read = zis.read(buffer, 0, (int) size)) > 0) { 
       Log.i("bitmap", new String(buffer, "UTF-8")); 
       byte[] decodedMap = Base64.decode(new String(buffer, "UTF-8"), Base64.DEFAULT); 
       Bitmap bitmap = BitmapFactory.decodeByteArray(decodedMap, 0, decodedMap.length); 
       Map map = new Map(zipEntry.getName().substring(0, zipEntry.getName().indexOf(".")), bitmap, id, level); 
       SharedData.maps.add(map); 
      } 
     } 
     zis.closeEntry(); 
    } 
    zis.close(); 

//這不是問題: 的問題是zis.read(buffer, 0, (int) size)不從文件中讀取的所有數據,所以我得到一個JSONException

編輯:

問題不從流中讀取數據讀取所有數據,但我認爲這個問題是編碼,這是JSONException:

09-19 14:30:23.216: W/System.err(7524): org.json.JSONException: Unterminated array at character 2959607 of 

的2959607是字符串

回答

0

問題是org.JSONArray它不能解析大串的長度,我取代它GSon現在工作正常

相關問題