How can I get the values ​​of this json?

advertisements

How can i get the value of "SEO-MOD-001"?

{
    "SEO": [
        {
            "SEO-MOD-001": {
                "SEO-END-001":  ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
                "SEO-END-002": [10, 6, 1, 2, 5, 7, 9, 12, 8, 6, 10, 7]
            }
        }
    ]
}


Download a Jar Name Json-simple-1.1.jar here

add it to you lib or Maven Dependency and A sample Code For You.

Json Object..
{
    "price":100,
    "name":"Vikrant Kashyap",
    "messages":["lsjdlfj","ljlsdkjfl2","ksdjfljlksd"]
}

Parsing Logic To this Object

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
public class JsonParsingExample {
     public static void main(String[] args) {

    JSONParser parser = new JSONParser();

    try {

        String obj = // this Contains the actual JSON Object as String.

        JSONObject jsonObject = (JSONObject) obj;

        String name = (String) jsonObject.get("name");
        System.out.println(name);

        long price= (Long) jsonObject.get("price");
        System.out.println(price);

        // loop array Message have a array in itself So It must be iterate Using     JsonArray Class
        JSONArray msg = (JSONArray) jsonObject.get("messages");
        Iterator<String> jsonIterator = msg.iterator();
        while (jsonIterator .hasNext()) {
            System.out.println(iterator.next());
        }

    } catch (Exception e)
        e.printStackTrace();
    }