Legacy Android utility to convert JSON objects into
application/x-www-form-urlencodedparameters — created to bridge compatibility gaps with older PHP backends that didn’t support raw JSON payloads.
This small library was built to solve a real interoperability issue: many legacy PHP backends (circa Android 4.x – 5.x) ignored application/json bodies and only accepted application/x-www-form-urlencoded data.
To work around this, I wrote a lightweight converter turning nested JSONObject or JSONArray structures into flattened key-value pairs compatible with libraries such as Loopj Android Async HTTP (RequestParams).
Although obsolete today, it remains a good example of problem-driven engineering, legacy compatibility, and pragmatic design under tight platform constraints.
- Converts any
JSONObject(including nested objects and arrays) into URL-encoded key/value pairs. - Generates PHP-style parameter names:
users[0][name]=Jeanusers[0][age]=24users[0][city]=Strasbourg, …
- Works out-of-the-box with
RequestParamsor any HTTP client expectingx-www-form-urlencoded. - No external dependencies — simple and portable.
JSONObject params = new JSONObject();
JSONArray users = new JSONArray();
JSONObject user = new JSONObject();
try
{
user.put("name", "Jean");
user.put("age", "24");
user.put("city", "Strasbourg");
users.put(user);
params.put("users", users);
}
catch(JSONException e)
{
// ...
}
RequestParams requestParams = JsonHelper.toRequestParams(params);
AsyncHttpClient client = new AsyncHttpClient();
client.post(context, url, requestParams, "application/x-www-form-urlencoded", new JsonHttpResponseHandler()
{
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response)
{
//...
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable e, JSONObject errorResponse)
{
// ...
}
})- Copy the
JsonHelper.java(converter) file into your Android project. - Convert your
JSONObjectbefore sending the request. - Use with your preferred HTTP client (Loopj, OkHttp wrapper, etc.).
⚠️ Note: This library exists for legacy compatibility only.
Modern APIs should send raw JSON (application/json) via Retrofit, OkHttp, or similar.
- Backward compatibility: adapting to systems that cannot evolve immediately.
- Data transformation: mapping nested JSON into flattened form-encoded structures.
- Pragmatic problem-solving: delivering a working bridge instead of rewriting entire systems.
- Maintainability: small, dependency-free, single-purpose utility.
This project is archived and kept online as a historical example of interoperability between Android clients and legacy PHP servers. It remains a reminder that *clean abstractions and problem-driven design can simplify even constrained environments.