Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7722693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:14:56+00:00 2026-06-01T04:14:56+00:00

I am using google api to get search result for certain queries in JSON

  • 0

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.

The JSON response format is :

{
 "kind": "customsearch#search",
 "url": {
  "type": "application/json",
  "template": "https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&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, 
   .
   .

Now I just want to access “items” array and my code is:

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<itemsArray.length();i++)
{
org.json.JSONObject newJSONObj=itemsArray.getJSONObject(i);
System.out.println("Title ::"+newJSONObj.getString("title"));
System.out.println("Link ::"+newJSONObj.getString("link"));
}

This code is giving NoSuchElementException for “items”.
Please help…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:14:58+00:00Added an answer on June 1, 2026 at 4:14 am

    If my brain is parsing this correctly, “queries” does not have “items” within it.

    "queries": {
      "nextPage": [
        {
        "title": "Google Custom Search - apple",
        "totalResults": "531000000",
        "searchTerms": "apple",
        "count": 10,
        "startIndex": 11,
        "inputEncoding": "utf8",
        "outputEncoding": "utf8",
        "safe": "off",
        "cx": "013036536707430787589:_pqjad5hr1a"
        } 
       ],  // end nextpage
    "request": [
      {
      "title": "Google Custom Search - apple",
      "totalResults": "531000000",
      "searchTerms": "apple",
      "count": 10,
      "startIndex": 1,
      "inputEncoding": "utf8",
      "outputEncoding": "utf8",
      "safe": "off",
      "cx": "013036536707430787589:_pqjad5hr1a"
      }
     ] // end request
    },  // end queries
    

    You want

    json.getJSONArray("items"); 
    

    I think.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application i want to get the weather report I'm using http://www.google.com/ig/api?weather= for
I am using google Api for custom search and have done the json Parsing.
I want to pass argument into google places url string. The string is @https://maps.googleapis.com/maps/api/place/search/xml?location=52.577798767,-2.124885567&radius=500&types=bank&sensor=false&key=AIzaSyCcC9pmri9XGOgyhjoHQq37cmcbfhjfghf6bBZe80
I'm using the Google Contacts API to get back formatted JSON, hopefully containing ALL
I'm using the Google API to get a user's location on this site .
Using the Google Maps API, how can I get the latitude and longitude of
I'm using google api 15 on android emulator. I want to specify a country
I am using Google map local search API and I'm trying to search and
I'm receiving deserialized object using WCF (trying to get latitude and longitude using google
How to create simple post/get API making simple calling to GAE database using Google

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.