0

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?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
AndroidEnthusiast
  • 6,557
  • 10
  • 42
  • 56

2 Answers2

1

String.format() doesn't like the %5D placeholder - %5D has to be %5d.
Reference: http://developer.android.com/reference/java/util/Formatter.html ... if it was about placeholders.

Anyway, it seems you just want the square brackets. Therefore, change this

String url = "http://api/doSomething.json?params%5Bemail%5D=%s"

to

String url = "http://api/doSomething.json?params[email]=%s"
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • %5d also results in the same exception. I tried using the second suggestion before going with the format. The square brackets cause a problem with the request – AndroidEnthusiast Nov 27 '15 at 12:47
  • 1
    You might want to have a look at this page: http://developer.android.com/reference/java/net/URLEncoder.html – Phantômaxx Nov 27 '15 at 12:52
0

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");
Community
  • 1
  • 1
AndroidEnthusiast
  • 6,557
  • 10
  • 42
  • 56