Java convert JSONObject to URL parameter

我们两清 提交于 2020-02-05 10:37:07

问题


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,


回答1:


Looks like, the only way I found it to make it manually.




回答2:


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.



来源:https://stackoverflow.com/questions/4518323/java-convert-jsonobject-to-url-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!