1

I have the following JSON data :

{
    "customer": [
        {
            "cus_name": "ravi sharma",
            "cus_email": "sk@yahoo.com",
            "cus_pass": "pass",
            "cus_mob": "91111111",
            "cus_add": "new delhi India",
            "cus_pass_reset_ques": "What is your lucky no.?",
            "cus_pass_reset_ans": "987"
        }
    ]
}

When I try to get cus_pass_reset_ques key data from JSON, getString() removes the spaces in string.

try {

    JSONArray earthquakes = json.getJSONArray("customer");

    for (int i = 0; i < earthquakes.length(); i++) {
        JSONObject e = earthquakes.getJSONObject(i);

        String a = e.getString("cus_name");
        String b = e.getString("cus_email");
        String c = e.getString("cus_pass");
        String d = e.getString("cus_mob");
        String h = e.getString("cus_add");
        String f = e.getString("cus_pass_reset_ques");
        String g  = e.getString("cus_pass_reset_ans");                  

    }
} catch (JSONException e) {
    Log.e("log_tag", "Error parsing data " + e.toString());
}

So how can I get the actual data as in above JSON.


This problem has been solved, thanks to - http://www.androidaspect.com/2013/05/android-json-parsing-tutorial.html

user2350535
  • 15
  • 1
  • 6

1 Answers1

0

It does that to minimize the number of bytes you send over the network.

use .toString(8) to keep them in, 8 is the number of spaces for each level of nesting.

Frank
  • 12,010
  • 8
  • 61
  • 78