Search code examples
androidjsonnetwork-programmingstring-formattingput

MissingFormatArgumentException with square brackets on android


I have this string which I'm trying to format:

String url = "http://api/doSomething.json?params%5Bemail%5D=%s"
String.format(url,email).

The idea is that it ends up looking like this:
http://api/doSomething.json?params[email]=aValue;

I'm currently getting a MissingFormatArgumentException, Format specifier: 5D exception.

Has anyone had issues with this before?


Solution

  • In the end i was able to resolve this using a URLEncoder.

    This post was particularly helpful -> URL encoding in Android

        String queryPart = String.format(PARAM_STRING,
                email);
        return baseUrl + URLEncoder.encode(queryPart, "utf-8");