I want to display a high score for my android from JSON. But I have error that said
value 100 at HS of type java.lang.Integer cannot be converted to JSONObject
here is the JSON looks like
{
"HS": 100
}
here is my code to show the value of the JSON
public void getData(){
AndroidNetworking.get("http://192.168.1.19/web_admin/public/api/highSkor_api")
.setPriority(Priority.LOW)
.build()
.getAsJSONObject(new JSONObjectRequestListener() {
@Override
public void onResponse(JSONObject response) {
//adding the product to product list
try {
//get JSON data
JSONObject data = response.getJSONObject("HS");
int HS = data.getInt("HS");
tx_hscore.setText(getString(R.string.high_score, HS);
Log.d(TAG, "ISI : "+HS);
} catch (JSONException e) {
e.printStackTrace();
}
//Toast.makeText(Result.this, "High Score : "+data_highSkor.getHighSkor(), Toast.LENGTH_LONG).show();
}
@Override
public void onError(ANError error) {
Log.e(TAG, "onError : "+ error);
Toast.makeText(Result.this, "Failed to reach server : "+error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
response.getInt("HS")and for me it works fine. Are you sure that the error is at the same line. Can you post your stack trace.