Thursday, 21 April 2016

parse JSON in Java

How to parse json in java .? Add org.json lib into your project 


public class PraseJSON {
    public static void main(String[] args) throws JSONException {
       String json = "{\n"
                + "   \"Name\": {\n"
                + "         \"Place\": \"Bangalore\",\n"
                + "         \"Age\": \"23\"\n"
                + "    }}";
              
               // + "}";

        PraseJSON classObject = new PraseJSON();
        JSONObject obj = new JSONObject(json);
        String name = obj.getJSONObject("Name").getString("Place");
        System.out.println("Name::"+name);


}}

No comments:

Post a Comment

Map class field to map

 import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; public class AutogeneratedClassMapper {     public static M...