我有以下代码:
<html>
<head>
<title>Ticket reservation form</title>
</head>
<body>
<form>
<table>
<tr>
<td colspan="2">
<h1 class="fontstyle"> AIRTICKET RESERVATON FORM</h1></td>
</tr>
<tr>
<td><span class="fontstyle">Customer Name :</span></td>
<td>
<input type="text" placeholder="ENTER NAME" />
</td>
</tr>
<tr>
<td><span class="fontstyle"> Specify your Class :</span>
</td>
<td>
<select id="s1"> <!--select tag starts-->
<option class="b">Select</option>
<option class="b" onchange="select()">Economy</option>
<option class="b" onchange="select()">FirstClass</option>
</select> <!--select tag closed-->
</td>
</tr>
<tr>
<td><span class="fontstyle"> Select your Seat :</span>
</td>
<td>
<select>
<option>Select</option>
<option disabled>Economy class </option> <!--economy class seats-->
<option class="economy">1</option>
<option class="economy">2</option>
<option class="economy">3</option>
<option class="economy">4</option>
<option class="economy">5</option>
<option disabled>First class </option> <!-- first class seats-->
<option class="first">6</option>
<option class="first">7</option>
<option class="first">8</option>
<option class="first">9</option>
<option class="first">10</option>
</select>
</td>
</tr>
</table>
</form>
</body>
</html>
我在第2行遇到异常:
java.lang.ClassCastException:java.util.HashMap $ EntrySet无法强制转换为java.util.HashSet
我的json输入是: {“key”:“4e32cd954f31320078c5fd218110c7ca”,“number”:“”,“unique_key”:“001”}
是什么原因以及如何解决这个问题?
答案 0 :(得分:1)
HashMap $ EntrySet与HashSet没什么共同点,因为这个转换失败
您应该迭代json的条目集并将以下值添加到您的HashSet
HashSet<Map.Entry<String,JsonElement>> map = new HashSet<>();
for(Map.Entry<String,JsonElement> entry : json.entrySet()){
if(entry != null) {
map.put(entry.getKey(), jsonObject.get(entry.getKey()));
}
}