Murtaza Murtaza - 3 months ago 18
JSON Question

How to change URL from JSON parsing

hi guys i am making an Android app which enlarge the Instagram profile pictures
i have done everything correctly now what i want is to modifiy the output url that i am getting from instagram server for example when i run my json script it give me this

https://instagram.fkhi6-1.fna.fbcdn.net/t51.2885-19/s320x320/20766978_110444579680760_4754914132547862528_a.jpg

and i want to convert this to that

https://instagram.fkhi6-1.fna.fbcdn.net/t51.2885-19/s800x800/20766978_110444579680760_4754914132547862528_a.jpg

here is my code that i am using

final JsonObjectRequest jsonRequest = new JsonObjectRequest(Request.Method.GET, finalURL, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {

try {

JSONObject user = response.getJSONObject("user");
String profilePicture = user.getString("profile_pic_url_hd");


Log.v("JSON", "User: " + profilePicture);
} catch (JSONException e) {

}

}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {

Log.v("FUN", "Error " + error.toString());


}
});


Thanks.

Answer Source

Try this:

String imageUrl=originalUrl.replaceAll("[s][0-9]+[x][0-9]+","s"+desiredWidth+"x"+desiredHeight);