Note that there are some explanatory texts on larger screens.

plurals
  1. POconverting google api search results obtained in json format into json object
    primarykey
    data
    text
    <p>I am using google api to get search result for certain queries in JSON format. Now I want to convert it into JSON Object in java and access only particular values.</p> <p>The JSON response format is :</p> <pre><code>{ "kind": "customsearch#search", "url": { "type": "application/json", "template": "https://www.googleapis.com/customsearch/v1?q={searchTerms}&amp;num={count?}&amp;start={startIndex?}&amp;lr={language?}&amp;safe={safe?}&amp;cx={cx?}&amp;cref={cref?}&amp;sort={sort?}&amp;filter={filter?}&amp;gl={gl?}&amp;cr={cr?}&amp;googlehost={googleHost?}&amp;c2coff={disableCnTwTranslation?}&amp;hq={hq?}&amp;hl={hl?}&amp;siteSearch={siteSearch?}&amp;siteSearchFilter={siteSearchFilter?}&amp;exactTerms={exactTerms?}&amp;excludeTerms={excludeTerms?}&amp;linkSite={linkSite?}&amp;orTerms={orTerms?}&amp;relatedSite={relatedSite?}&amp;dateRestrict={dateRestrict?}&amp;lowRange={lowRange?}&amp;highRange={highRange?}&amp;searchType={searchType}&amp;fileType={fileType?}&amp;rights={rights?}&amp;imgSize={imgSize?}&amp;imgType={imgType?}&amp;imgColorType={imgColorType?}&amp;imgDominantColor={imgDominantColor?}&amp;alt=json" }, "queries": { "nextPage": [ { "title": "Google Custom Search - apple", "totalResults": "531000000", "searchTerms": "apple", "count": 10, "startIndex": 11, "inputEncoding": "utf8", "outputEncoding": "utf8", "safe": "off", "cx": "013036536707430787589:_pqjad5hr1a" } ], "request": [ { "title": "Google Custom Search - apple", "totalResults": "531000000", "searchTerms": "apple", "count": 10, "startIndex": 1, "inputEncoding": "utf8", "outputEncoding": "utf8", "safe": "off", "cx": "013036536707430787589:_pqjad5hr1a" } ] }, "context": { "title": "Custom Search" }, "searchInformation": { "searchTime": 0.206589, "formattedSearchTime": "0.21", "totalResults": "531000000", "formattedTotalResults": "531,000,000" }, "items": [ { "kind": "customsearch#result", "title": "Apple", "htmlTitle": "\u003cb\u003eApple\u003c/b\u003e", "link": "http://www.apple.com/", "displayLink": "www.apple.com", "snippet": "Apple designs and creates iPod and iTunes, Mac laptop and desktop computers, the OS X operating system, and the revolutionary iPhone and iPad.", "htmlSnippet": "\u003cb\u003eApple\u003c/b\u003e designs and creates iPod and iTunes, Mac laptop and desktop computers, \u003cbr\u003e the OS X operating system, and the revolutionary iPhone and iPad.", "cacheId": "5iRmnZTn43cJ", "formattedUrl": "www.apple.com/", "htmlFormattedUrl": "www.\u003cb\u003eapple\u003c/b\u003e.com/", "pagemap": { "cse_image": [ { "src": "http://images.apple.com/home/images/ipad_hero.jpg" } ], "cse_thumbnail": [ { "width": "348", "height": "145", "src": "https://encrypted-tbn3.google.com/images?q=tbn:ANd9GcQRUCTcMJO12wSHtTA8iXXzdoaHo1ssBW8cyP5ZONgIdpFtr9gNxmRdruk" } ], "metatags": [ { "author": "Apple Inc.", "viewport": "width=1024", "omni_page": "Apple - Index/Tab" } ] } }, { "kind": "customsearch#result", "title": "Official Apple Store - Buy the new iPad, Apple TV, . . </code></pre> <p>Now I just want to access "items" array and my code is:</p> <pre><code>org.json.JSONObject json=null; json = new JSONObject(jsonResponse); org.json.JSONObject queryArray=json.getJSONObject("queries"); org.json.JSONArray itemsArray=queryArray.getJSONArray("items"); for(int i=0;i&lt;itemsArray.length();i++) { org.json.JSONObject newJSONObj=itemsArray.getJSONObject(i); System.out.println("Title ::"+newJSONObj.getString("title")); System.out.println("Link ::"+newJSONObj.getString("link")); } </code></pre> <p>This code is giving NoSuchElementException for "items". Please help...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload