skip to Main Content

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]
            }
        }
    ]
}

2

Answers


  1. 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();
        }
    
    Login or Signup to reply.
  2. var data = jQuery.parseJSON('{"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] }}]}')
    
    data.SEO[0]['SEO-MOD-001']['SEO-END-001']
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search