0
String getCity = request.getParameter("name1");
HttpSession session = request.getSession();
try {
ConnectToDb db = new ConnectToDb();
con =db.getConnect();
pstmt = con.prepareStatement("select Name, CountryCode, District, Population from city where name =?");
pstmt.setString(1, getCity);
rs=pstmt.executeQuery();
ArrayList<getCity> getinfo = new ArrayList<getCity>();
while(rs.next()){
getCity gc = new getCity();
gc.setCity(rs.getString("name"));
gc.setContryCode(rs.getString("CountryCode"));
gc.setDistrict(rs.getString("district"));
gc.setPopulation(rs.getString("population"));
getinfo.add(gc);
}
JSONObject jobj = new JSONObject();
jobj.put("city", getinfo);
System.out.println(jobj);
} catch (Exception e) {
System.out.println(e.getMessage());
}
输出:为什么JSON存储对象像这样{ “城市”:[{ “com.getcity @ FAE87A。”}]}
{"city":[{"city":"Perm","district":"Perm","contryCode":"RUS","population":"1009700"}]}
但相同的代码,当我在其他计算机上执行输出会像这样:{"city":[{"[email protected]"}]}
。
为什么会发生这种情况?
看起来像应该返回城市部分是失败的部分,并返回网址也许它从它? –