Pretty simple question, I think? How can I create a JSON file and insert (append) the new data I requested (GET) from Volley. So to recap, create file and append it the response I GET. Thanks!
// Formulate the request and handle the response.
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, (String )null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Toast.makeText(getActivity(), response.toString() , Toast.LENGTH_LONG).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Error Fetching Data", Toast.LENGTH_LONG).show();
}
});
mRequestQueue.add(jsonObjectRequest);
How I read the file when it exists on the user's phone (Pretty unimportant, but nonetheless gives context)
public String loadJSONFromAsset() {
String json = null;
try {
InputStream is = getActivity().getAssets().open("test12.json");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");
} catch (IOException ex) {
Toast.makeText(getActivity(), "Error Fetching Data", Toast.LENGTH_LONG).show();
return null;
}
return json;
}
Thanks!!