0

I am trying to break my JSON result into new lines, but finding it difficult to do. e.g, {"id":"1","student_id":"5013","subject1":"87","subject2":"87","subject3":"56","subject4":"76","subject5":"68","subject6":"58","subject7":"98","subject8":"67","subject9":"88"}

to

    id : 1
    student_id : 5013
    subject1 : 87
    subject2 : 87
...

I tried using

    String[] stringsArray = new String[jArray.length()];
             for (int i = 0; i < jArray.length(); i++) {
                    System.out.println(stringsArray[i] = jObj.getString(i) + "\n");
}

but still giving same result. Thanks.

Derin S
  • 55
  • 1
  • 10
  • 4
    Possible duplicate of [How to parse JSON in Java](http://stackoverflow.com/questions/2591098/how-to-parse-json-in-java) – Jérôme May 17 '17 at 13:58
  • https://developer.android.com/reference/org/json/JSONArray.html#toString(int) – JB Nizet May 17 '17 at 13:58
  • Are you trying to parse the JSON or just pretty print? – bradimus May 17 '17 at 13:58
  • 1
    all i want to do is just to print, i am not parsing the JSON – Derin S May 17 '17 at 14:01
  • `System.out.println("stringsArray[i] = " + jObj.getString(i) + "\n");`? – bradimus May 17 '17 at 14:02
  • What output are you getting? – bradimus May 17 '17 at 14:03
  • thanks for that, but it is still giving that same string please. talking about {"id":"1","student_id":"5013","subject1":"87","subject2":"87","subject3":"56","subject4":"76","subject5":"68","subject6":"58","subject7":"98","subject8":"67","subject9":"88"} – Derin S May 17 '17 at 14:12
  • Have you looked at [`String::replaceAll`](https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#replaceAll-java.lang.String-java.lang.String-)? – bradimus May 17 '17 at 14:16
  • 1
    thanks so much @bradimus, i have been able to get it using [this](http://stackoverflow.com/a/25683910/7000849) . I sincerely do appreciate your time. – Derin S May 17 '17 at 14:27

0 Answers0