2016-01-20 37 views
-2

當我嘗試加載兩個文件時出現錯誤。 我的問題是如何將兩個json文件加載到領域。如何加載兩個json文件?

以下是加載JSON文件:

private void loadJsonFromStream() throws IOException { 

    InputStream stream = getAssets().open("school.json"); 

    realm.beginTransaction(); 
    try { 
     realm.createAllFromJson(School.class, stream); 
     realm.commitTransaction(); 
    } catch (IOException e) { 
     // Remember to cancel the transaction if anything goes wrong. 
     realm.cancelTransaction(); 
    } finally { 
     if (stream != null) { 
      stream.close(); 


     } 
    } 

} 

被加載設置設置文件以下。

private void loadJsonSettingFromStream() throws IOException { 

    InputStream streamSetting = getAssets().open("setting.json"); 

    realm.beginTransaction(); 
    try { 

     realm.createAllFromJson(Setting.class, streamSetting); 
     realm.commitTransaction(); 
    } catch (IOException e) { 
     // Remember to cancel the transaction if anything goes wrong. 
     realm.cancelTransaction(); 
    } finally { 
     if (streamSetting != null) { 
      streamSetting.close(); 


     } 
    } 
+1

顯示你的錯誤可能會讓別人給你更好的幫助。 – InbetweenWeekends

回答

1

「預期的布爾但NUMBER」

我猜你用0和1來表示布爾值,而不是在JSON文件「真」與「假」的字符串。

更改pojo或json的結構。如果這些不是選項,您可以輕鬆編寫自定義分析器來將整數映射爲布爾值。