gpt4 book ai didi

java - 为什么 JSON 存储这样的对象 {"city":[ {"com.getcity.@FAE87A"}]}

转载 作者:行者123 更新时间:2023-12-02 03:33:17 25 4
gpt4 key购买 nike

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());
}

输出:

{"city":[{"city":"Perm","district":"Perm","contryCode":"RUS","population":"1009700"}]}

但是当我在其他机器输出中执行相同的代码时,会得到如下所示的内容:{"city":[{"com.getCity.@AF345E"}]}

为什么会出现这种情况?

最佳答案

com.getCity.@AF345E

它是一个“getCity”对象,没有实现“toString”方法。检查您的代码。

关于java - 为什么 JSON 存储这样的对象 {"city":[ {"com.getcity.@FAE87A"}]},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37771144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com