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()但结果是一样的。我该怎么办?
答案 0 :(得分:1)
obj.get("Location")
返回JSONObject,因此首先从Location
获取obj
JSONObject以及latitude
和longitude
值:
JSONObject jsonLocation = obj.getJSONObject("Location");
double latitude=jsonLocation.getDouble("latitude");
double longitude=jsonLocation.getDouble("longitude");
location=new ParseGeoPoint(latitude, longitude)