-3

I have a JSON Array as follows:

jSONArray: {"li":[["apple\r\n","orange\r\n","mango\r\n"]]}

I want only the list as [apple, orange, mango] in android. Can anybody explain how to parse it in android without \r\n. I have tried as follows:

JSONArray jsonArray1 = new JSONArray(results.toString());  // which is the JSON Array
                    for(int i=0; i < jsonArray1.length(); i++) {
                        JSONObject jsonobject = new JSONObject();
                        JSONObject issue = jsonArray1.getJSONObject(i);
                        String _pubKey = issue.getString("li");
                        }

So, I am getting pubKey as [["apple\r\n","orange\r\n","mango\r\n"]]. I dont want \r\n.

Vishnu
  • 97
  • 4
  • 11

1 Answers1

1

Just replace those characters while parsing.

Example: If fruit is the string you want to put in your JSONArray jsonArray, call:

jsonArray.put(fruit.trim().replace("\r", "").replace("\n", ""));
0101100101
  • 5,786
  • 6
  • 31
  • 55