2 years ago
#45425
Shweta
How to resolve this error? java.lang.String cannot be converted to JSONObject
I am trying to set value for sponsorID to the textview but but I'm not able to parse response to lineetSponsor_name.setText(strSponsorId);
this is my code
TextView sponsorName,etSponsor_name;
String strSponsorId = "";
sponsorId.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
strSponsorId = sponsorId.getText().toString();
String url = Config.URL + "webapi/fortuneapi.asmx/CheckSponcer?SponcerID=" + strSponsorId;
Log.d("TAG", url);
StringRequest stringRequest = new StringRequest(url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("TAG", "SponcerID: " + response);
try {
JSONObject jsonObject = new JSONObject(response);
strSponsorId = jsonObject.optString("SponsorID","");
Log.i("TAG", "parseData: " + strSponsorId);
etSponsor_name.setText(strSponsorId);
} catch (Exception e) {
Log.d("TAG", "SponcerIDException: " + e);
}
Log.d("TAG", "SponcerID_EX_Response: " + response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("TAG", "onErrorResponse_of_sponcerID: " + error.getMessage());
}
});
RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
queue.add(stringRequest);
}
});
StackTrace:
2022-01-13 15:03:17.755 24864-24864/com.example.fortuinelife D/TAG: https://fortunelife.asia/webapi/fortuneapi.asmx/CheckSponcer?SponcerID=sai
2022-01-13 15:03:18.203 24864-24864/com.example.fortuinelife D/TAG: SponcerID: <?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">Fortune Life</string>
2022-01-13 15:03:18.204 24864-24864/com.example.fortuinelife D/TAG:
SponcerIDException: org.json.JSONException: Value <?xml of type
java.lang.String cannot be converted to JSONObject
android
json
android-studio
parsing
jsonparser
0 Answers
Your Answer