1

What is the elegant way to convert JSONObject to URL parameters. For example, JSONObject:

{stat: {123456: {x: 1, y: 2}, 123457: {z: 5, y: 2}}}}

this should be like:

stat[123456][x]=1&stat[123456][y]=2&stat[123457][z]=5&stat[123457][y]=2

of course with escaped symbols, and of course JSON object could be more complicated.. Maybe there already exist some mechanisms for that?

Thanks,

3
  • You could use an HTTP POST instead. Commented Dec 23, 2010 at 11:31
  • I'm using POST, but you have to pass parameters first... Commented Dec 23, 2010 at 11:43
  • 1
    I think Marcelo is suggesting that you send the actual JSON as your POST data. When using POST, it's not mandatory to use the application/x-www-form-urlencoded format (i.e. key=value) Commented Dec 23, 2010 at 12:24

1 Answer 1

1

If readability isn't a big concern, you could base64-encode the JSON string in the url, and then base64-decode inside the web server before decoding the JSON itself.

Sign up to request clarification or add additional context in comments.

1 Comment

That looks like a custom format that is very unlikely to be supported by any general purpose library. You'll probably have to write an algorithm yourself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.