[英].asFormUrlEncoded() to retrieve data from hashMap<String, String>
I'm sending a video file along with some user details to my play framework application using MultipartRequest, the user details are added to a hashmap Map<String, String> myMap;
我正在使用MultipartRequest将视频文件以及一些用户详细信息发送到我的播放框架应用程序,这些用户详细信息已添加到哈希映射Map<String, String> myMap;
on the server side I have retrieved my video file using . 在服务器端,我已经使用检索了我的视频文件。 asMultipartFormData();
I was trying to retrieve my map using . 我正在尝试使用检索地图。 asFormUrlEncoded();
but that uses Map<String, String[]>
但这使用Map<String, String[]>
So I've only been able to retrieve one value from my hash map, if I try to retrieve anymore using this code 因此,如果我尝试使用此代码再检索一次,则只能从哈希映射中检索一个值
for(int i =0; i < myMap.size(); i++){
String param = "param" + (i + 1);
System.out.println(myMap.get(param)[i]);
}
I get an arrayOutOfBounds error, is there an alternative solution to retrieve the data from the MultipartFormData, or can I implement my loop differently? 我收到arrayOutOfBounds错误,是否有其他解决方案可从MultipartFormData检索数据,还是可以不同地实现循环?
maybe I shouldn't be using .asFormUrlEncoded();
也许我不应该使用.asFormUrlEncoded();
at all to retrieve the hashmap? 根本无法检索哈希图?
EDIT 编辑
I've modifed my code to use an iterator 我已经修改了代码以使用迭代器
Iterator<String> myVeryOwnIterator = myMap.keySet().iterator();
while(myVeryOwnIterator.hasNext()) {
String key=(String)myVeryOwnIterator.next();
String[] value= myMap.get(key);
System.out.println(key + " " + value);
}
This prints my key, but returns Ljava.lang.String;@
for the values, I think this is because the .asFormUrlEncoded();
这将打印我的密钥,但是返回Ljava.lang.String;@
作为值,我认为这是因为.asFormUrlEncoded();
is expecting a <String, string[]>
, but my hashMap uses <String, String>
any solution to this? 期待<String, string[]>
,但是我的hashMap使用<String, String>
对此有任何解决方案?
This was the solution: 这是解决方案:
Iterator<String> myVeryOwnIterator = myMap.keySet().iterator();
while(myVeryOwnIterator.hasNext()) {
String key=(String)myVeryOwnIterator.next();
String[] value= myMap.get(key);
System.out.println(key + " " + value[0]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.