Get all the Links from Bing Search api and add them to array



I have a question, because I am new to Bing Search API and I am not familiar how to use it. I am trying to get all the links from the Bing search result. So I am searching for keyword. Is working but I want to get the links of the results that I got from the Bing Search API that I have included in my Java application. The problem is that I want to retrieve and save the links into an array. So I am using XML to parse it to JSON. But the main problem when i am trying to get the Urls or links I cannot get them. Does anyone has an idea how to do it or where I am doing it wrong?


I want for example to get http://ift.tt/1Bwd6sf (one of the search results of Bing search API)


Here is some of the code:



String str = "http://ift.tt/157uWoz";
URL url = new URL(str);
InputStream is = url.openStream();
int ptr = 0;
StringBuilder builder = new StringBuilder();
while ((ptr = is.read()) != -1) {
builder.append((char) ptr);
}
String xml = builder.toString();

JSONObject jsonObject = XML.toJSONObject(xml);
System.out.println(jsonObject.toString());
System.out.println(jsonObject.get("id"));


some of the output:



"feed":{"entry":[{"id":"http://ift.tt/1Bwd6IC' what is omonoia'&$skip=0&$top=1","title":{"type":"text","content":"WebResult"},"updated":"2015-01-15T14:35:57Z","content":{"m:properties":{"d:Url":{"content":"http://ift.tt/157uUgA","m:type":"Edm.String"},"d:DisplayUrl":{"content":"http://ift.tt/157uUgA","m:type":"Edm.String"},"d:Title":{"content":"AC Omonia - Wikipedia, the free encyclopedia","m:type":"Edm.String"},"d:Description":{"content":"Athletic Club Omonoia Nicosia, commonly referred to as Omonoia, is a Cypriot professional football club based in the capital city, Nicosia. The club was established ...","m:type":"Edm.String"},"d:ID":{"content":"88cf85ab-f077-4f2b-8037-f3d3447b9d34","m:type":"Edm.Guid"}},"type":"application/xml"}},{"id":"http://ift.tt/1Bwd6IC' what is omonoia'&$skip=1&$top=1","title":{"type":"text","content":"WebResult"},"updated":"2015-01-15T14:35:57Z","content":{"m:properties":{"d:Url":{"content":"http://ift.tt/1Bwd6sf","m:type":"Edm.String"},"d:DisplayUrl":{"content":"http://ift.tt/1Bwd6sf","m:type":"Edm.String"},"d:Title":{"content":"Omonoia - Wikipedia, the free encyclopedia","m:type":"Edm.String"},"d:Description":{"content":"Omonoia may refer to: Omonoia Square, one of Athens' main squares, Omonoia Station, the subway station located on the square or Omonoia, the neighborhood around it.","m:type":"Edm.String"},"d:ID":{"content":"4668962f-c8cb-43b1-a12d-19d8aee944bb","m:type":"Edm.Guid"}},"type":"application/xml"}},{"id":"http://ift.tt/1Bwd6IC' what is omonoia'&$skip=2&$top=1","title":{"type":"text","content":"WebResult"},"updated":"2015-01-15T14:35:57Z","content":{"m:properties":{"d:Url":{"content":"http://ift.tt/1Bwd83p","m:type":"Edm.String"},"d:DisplayUrl":{"content":"http://ift.tt/1Bwd83p","m:type":"Edm.String"},"d:Title":{"content":"Athens/Omonia - Wikitravel - The Free Travel Guide","m:type":"Edm.String"},"d:Description":{"content":"Omonia Square is the center of Athens, and is composed of the actual square together with the surrounding streets, open areas and assemblage of grand buildings that ...","m:type":"Edm.String"},"d:ID":{"content":"b711b509-d478-48c4-ad44-51e9d87a5646","m:type":"Edm.Guid"}},"type":"application/xml"}},{"id":"http://ift.tt/1Bwd6IC' what is omonoia'&$skip=3&$top=1","title":{"type":"text","content":"WebResult"},"updated":"2015-01-15T14:35:57Z","content":{"m:properties":{"d:Url":{"content":"http://ift.tt/157uUwX","m:type":"Edm.String"},"d:DisplayUrl":{"content":"http://ift.tt/157uUwX","m:type":"Edm.String"},"d:Title":{"content":"OMONOIA Vs ANORTHOSI 3-2 - YouTube","m:type":"Edm.String"},"d:Description":{"content":"OMONOIA Vs ANORTHOSI 3-2 - YouTube ... YouTube home","m:type":"Edm.String"},"d:ID":{"content":"a8870310-3a66-493e-9155-3608501305d2","m:type":"Edm.Guid"}},"type":"application/xml"}},{"id":"http://ift.tt/1Bwd6IC' what is omonoia'&$skip=4&$top=1","title":{"type":"text","content":"WebResult"},"updated":"2015-01-15T14:35:57Z","content":{"m:properties":{"d:Url":{"content":"http://ift.tt/1Bwd8jF","m:type":"Edm.String"},"d:DisplayUrl":{"content":"http://ift.tt/1Bwd8jF","m:type":"Edm.String"},"d:Title":{"content":"OMONOIA Vs APOLLON 2-4 - YouTube","m:type":"Edm.String"},"


Some source code I got them from this question: Parsing external XML to JSON in Java?


No comments:

Post a Comment