gpt4 book ai didi

android - org.json.JSONObject 无法转换为 com.parse.ParseGeoPoint

转载 作者:行者123 更新时间:2023-11-29 01:34:43 25 4
gpt4 key购买 nike

private class MyObject {
private String itemName;
private int itemPrice;
private ParseGeoPoint location;
private MyObject(JSONObject obj) {
try {
itemName = obj.getString("Item").toLowerCase().trim();
itemPrice = obj.getInt("Price");
location = (ParseGeoPoint) obj.get("Location");
} catch (Exception e) {
Utility.showMessage(e.getMessage(), "Oops!", SalesReportActivity.this);
}
}
public String toString() {
return "Name: " + itemName + "\n" +
"Price: " + itemPrice;
}
}

对于上面的代码,Android 给出了上面的异常。我也试过 getJSONObject() 但结果是一样的。我该怎么办?

最佳答案

obj.get("Location")返回JSONObject,所以先得到Location来自 obj 的 JSONObject和两个latitudelongitude值(value)观:

            JSONObject jsonLocation = obj.getJSONObject("Location");
double latitude=jsonLocation.getDouble("latitude");
double longitude=jsonLocation.getDouble("longitude");
location=new ParseGeoPoint(latitude, longitude)

关于android - org.json.JSONObject 无法转换为 com.parse.ParseGeoPoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29069748/

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