由于我不熟悉这种情况,我会先进道歉。在Hash Map中将JSONObject整数转换为浮点值是否有解决方法?我在Android环境中创建它。
double value;
private Map<String, Float> getPricing() {
final Map<String, Float> m = new HashMap<>();
m.put("AAA", (float) value);
m.put("BBB", 0.747049f);
//remove some list to shorten the code
return m;
}
RequestQueue queue = Volley.newRequestQueue(this);
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject json = new JSONObject(response);
JSONObject jsonStore = json.getJSONObject("quotes");
value = jsonStore.getDouble("rack");
// just a replicate to check if JSON is not null when log or Toast
replicate = jsonStore.getDouble("rack");
} catch (JSONException e) {
e.printStackTrace();
Log.i("Response", "Error");
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i("Response", "Error");
}
}
);
queue.add(stringRequest);
我记录并Toast JSONobject并验证它有一个值但是当它转换为float时它返回0.任何指导都非常感谢。美好的一天