A simple Android library to open JSON from assets
Grab the latest dependencies through Gradle, add it to your build.gradle with:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
and:
dependencies {
implementation 'com.github.zainfikrih:jsonloader-library:{latest version}'
}
Put the json file in the assets package on the android project (src / main / assets / filename.json). For more information, see Where do I place the 'assets' folder in Android Studio?
Get JSON as a string:
JSONLoader.with(getApplicationContext())
.fileName("filename.json")
.get(new StringLoaderListener() {
@Override
public void onResponse(String response) {
// response as String
}
@Override
public void onFailure(IOException error) {
// error
}
});
Get JSON as JSON Object:
JSONLoader.with(getApplicationContext())
.fileName("filename.json")
.getAsJSONObject(new JSONObjectLoaderListener() {
@Override
public void onResponse(JSONObject response) {
// response as JSONObject
}
@Override
public void onFailure(Exception error) {
// error
}
});
Get JSON as JSON Array:
JSONLoader.with(getApplicationContext())
.fileName("filename.json")
.getAsJSONArray(new JSONArrayLoaderListener() {
@Override
public void onResponse(JSONArray response) {
// response ad JSONArray
}
@Override
public void onFailure(Exception error) {
// error
}
});
For some examples, see the sample App.
Copyright 2019 Zain Fikri H
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.