将 HashMaps 值传递给 url
我的数据存储在 HashMap 中,我想将此数据传递到一个 url,但我希望它保持分组在一起。我正在考虑序列化 HashMap,然后将该数据传递给 PHP,然后取消序列化。我的第二个选择是将数据传递到 JSON,然后将其传递到 url。
有人对此有什么建议或更好的解决方案吗?
例子:
//Has Data added to hash map
HashMap hashmap1=new HashMap();
//Has Data added to hash map
HashMap hashmap2=new HashMap();
//dateEncoded Method
//Will encode data by serializing it or passing it to JSON
String data = URLEncoder.encode(dataEncoded(hashmap1), "UTF-8") + "=" + URLEncoder.encode("10", "UTF-8");
data += "&" + URLEncoder.encode(dataEncoded(hashmap2), "UTF-8");
// Send data
URL url=new URL("http://localhost/index.php?"+data);
I have data stored in HashMaps and I would like to pass this data to a url but I want it to remained grouped together. I am thinking of serializing the HashMaps and then passing that data to PHP and then unserailzing. My second alternative will be passing the data to JSON and then passing it into a url.
Does anyone have any suggestions for this or a better solution?
Example:
//Has Data added to hash map
HashMap hashmap1=new HashMap();
//Has Data added to hash map
HashMap hashmap2=new HashMap();
//dateEncoded Method
//Will encode data by serializing it or passing it to JSON
String data = URLEncoder.encode(dataEncoded(hashmap1), "UTF-8") + "=" + URLEncoder.encode("10", "UTF-8");
data += "&" + URLEncoder.encode(dataEncoded(hashmap2), "UTF-8");
// Send data
URL url=new URL("http://localhost/index.php?"+data);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要您假设找到的所有对都需要出现在映射中,参数名称/值对就可以正常工作。
Parameter name/value pairs will work just fine, as long as you assume that all the pairs you find need to end up in the map.