将 HashMaps 值传递给 url

发布于 2024-11-17 09:14:47 字数 670 浏览 2 评论 0原文

我的数据存储在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葬シ愛 2024-11-24 09:14:47

只要您假设找到的所有对都需要出现在映射中,参数名称/值对就可以正常工作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文