0

I am trying to parse the following JSON String, but I can't figure out how to get to the title nd href strings.

Can anyone help me?

{  
   "status":{  
      "code":200,
      "http":"Fetched (ring) 200 450 and parsed 1/10 entries",
      "nextFetch":1418084814,
      "entriesCountSinceLastMaintenance":1,
      "period":450,
      "lastFetch":1418084364,
      "lastParse":1418084364,
      "lastMaintenanceAt":1418017613,
      "feed":"http://www.ncataggies.com/rss.dbml?db_oem_id=24500&media=results"
   },
   "permalinkUrl":"http://www.ncataggies.com/",
   "standardLinks":{  
      "alternate":[  
         {  
            "title":"North Carolina A&T  Results",
            "rel":"alternate",
            "href":"http://www.ncataggies.com/",
            "type":"text/html"
         }
      ],
      "self":[  
         {  
            "title":"North Carolina A&T  Results",
            "rel":"self",
            "href":"http://www.ncataggies.com/rss.dbml?db_oem_id=24500&media=results",
            "type":"application/rss+xml"
         }
      ]
   },
   "title":"North Carolina A&T  Results",
   "updated":1418077800,
   "id":"north-carolina-a-t-results-2014-12-8-22",
   "items":[  
      {  
         "id":"http://www.ncataggies.com//SportSelect.dbml?DB_OEM_ID=24500&SPID=74519&SPSID=593466&Q_SEASON=2014&SCH_ID=5710847",
         "published":1418077800,
         "updated":1418077800,
         "title":"Women's Basketball: vs UMES (12/08/2014) - L (43-58)",
         "summary":"<p>at Princess Anne, Md. - 5:30 PM -\n\t\t\t\t\n\t\t\t\t</p>",
         "standardLinks":{  
            "self":[  
               {  
                  "title":"Women's Basketball: vs UMES (12/08/2014) - L (43-58)",
                  "rel":"self",
                  "href":"http://www.ncataggies.com//SportSelect.dbml?DB_OEM_ID=24500&SPID=74519&SPSID=593466&Q_SEASON=2014",
                  "type":"application/rss+xml"
               }
            ]
         }
      }
   ]
}

I don't have much experience with JSON, this is the JAVA I have so far:

    JSONObject obj = new JSONObject(json);
    JSONArray items = (JSONArray) obj.get("items");
    System.out.println(items.get(1).toString());
user1154644
  • 4,491
  • 16
  • 59
  • 102

1 Answers1

0
import org.json.*;

    JSONObject obj = new JSONObject(json);
    JSONArray items = (JSONArray) obj.get("items");

    for(int i=0;i<items.length;i++)
    {
      JSONObject item = items.getJSONObject(i);
      JSONObject standardLinks = item.getJSONObject("standardLinks");
      JSONArray self = standardLinks.getJSONArray("self");
      JSONObject selfItem = self.getJSONObject(0);
      System.out.println(selfItem.getString("href"));
      System.out.println(selfItem.getString("title"));  
    }

Try this. I didn't compile the code. Please correct the syntax error, if any.

Vishal Zanzrukia
  • 4,902
  • 4
  • 38
  • 82