中希望將空值替換爲空白,其中數據來自JSON格式。將空值替換爲空白
下面是響應有一些數據值爲空的代碼我不想在我的應用程序顯示空,所以我能做些什麼來將null更改爲空白。
String detailsURL = "http://10.0.2.2/xp/details2.php?id="+id+"&gender="+strGender+"&curr_user_id="+current_Id;
StringRequest stringRequest = new StringRequest(Request.Method.GET,detailsURL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("details*************",response.trim());
showJSON(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(BlankActivity.this,error.getMessage().toString(),Toast.LENGTH_LONG).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(BlankActivity.this);
requestQueue.add(stringRequest);
下面是showJSON功能
private void showJSON(String response){
String fname = "";
String lname = "";
String mobile1 = "";
String emailVC = "";
String height = "";
String weight = "";
String complexion = "";
String body = "";
String diet = "";
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY);
JSONObject userData = result.getJSONObject(0);
fname = userData.getString(Config.KEY_FNAME);
lname = userData.getString(Config.KEY_LNAME);
mobile1 = userData.getString(Config.KEY_MOBILE1);
emailVC = userData.getString(Config.KEY_EMAIL);
height = userData.getString(Config.KEY_HEIGHT);
weight = userData.getString(Config.KEY_WEIGHT);
complexion = userData.getString(Config.KEY_COMPLEXION);
body = userData.getString(Config.KEY_BODY);
diet = userData.getString(Config.KEY_DIET);
後showJSON方法 – Raghavendra
我已經發布showJSON方法請檢查 –
它是連擊所有字符串值中的「」(空白),如果如果Array [](空數組),----- ------ so batter to change at service side –