Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saved jsonStringList as a textfile and had problems loading #2

Open
kehems opened this issue Jan 24, 2020 · 1 comment
Open

Saved jsonStringList as a textfile and had problems loading #2

kehems opened this issue Jan 24, 2020 · 1 comment

Comments

@kehems
Copy link

kehems commented Jan 24, 2020

Saved jsonStringList as a textfile in the asset folde and had problems loading.

see code:

private void NLevelExpandableListView(){
// String jsonStringList = getAssetJsonData(getApplicationContext());

    String json = "";
    try {
        InputStream inputStream = getAssets().open("test.txt");
        int size = inputStream.available();
        byte[] buffer = new byte[size];
        inputStream.read(buffer);
        inputStream.close();
        json = new String(buffer);

    }  catch (IOException ex){
        ex.printStackTrace();
    }

    Log.i("Control", json);
    String jsonStringList = "json";

Logcat display.....
2020-01-24 14:40:03.702 18888-18888/com.example.orcoa I/Control: [{"title": "Class 1 Accounts of Durable Resources", " +
""children":[{"title":" 10 Capital", " +
""children":[{"title":"Extended Child 111", " +
""children":[{"title":"Super Extended Child 1111"," +
""children":[]}]},{"title":"Extended Child 112"," +
""children":[]},{"title":"Extended Child 113","children":[]}]}," +
"{"title":"Child 12", " +
""children":[{"title":"Extended Child 121"," +
""children":[]},{"title":"Extended Child 122", " +
""children":[]}]},{"title":"Child 13", "children":[]}]}, " +

                "{\"title\":\"Class 2\", \"children\":" +
                "[{\"title\":\"Child 21\", \"children\":" +
                "[{\"title\":\"Extended Child 211\", \"children\":[]}," +
                "{\"title\":\"Extended Child 212\", \"children\":[]}," +
                "{\"title\":\"Extended Child 213\", \"children\":[]}]}," +
                "{\"title\":\"Child 22\", \"children\":" +
                "[{\"title\":\"Extended Child 221\", \"children\":[]}," +
                "{\"title\":\"Extended Child 222\", \"children\":[]}]}," +
                "{\"title\":\"Child 23\", \"children\":[]}]}," +


                "{\"title\":\"Class 3\",\"children\":[]}]

App does work as before. What could be wrong. Thanks in advance

@alimogh
Copy link

alimogh commented Jul 25, 2021

Hello
error :
String jsonStringList = "json";

good code :
String jsonStringList = json;

or
please check with this method :

public String initJSONFile() {
String json = null;
try {
InputStream is = getAssets().open("Your.json.txt");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
return json;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants