-4
{"result":[{"heading":"The City School","text":"Established in 1978"}]}

please help printing this type to json format?

Sathish Kumar J
  • 4,280
  • 1
  • 20
  • 48
Jhon Peter
  • 1
  • 1
  • 2

2 Answers2

2

Use GSON for pretty-printting.

Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonParser jp = new JsonParser();
JsonElement je = jp.parse(uglyJSONString);
String prettyJsonString = gson.toJson(je);
thangdc94
  • 1,542
  • 2
  • 26
  • 38
0

Try this code

String jsonStr = "{'result':[{'heading':'The City School','text':'Established in 1978'}]}";

try {
    JSONObject jsonObj = new JSONObject(jsonStr);
    String headingVal=jsonObj.getDouble("heading");
    String textVal=jsonObj.getDouble("text");
    System.out.println("Heading --"+headingVal);
    System.out.println("Text--"+textVal);                           
} catch (JSONException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
Android Surya
  • 544
  • 3
  • 17