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 6591501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:25:52+00:00 2026-05-25T17:25:52+00:00

I have a JSON of this format with dynamic keys for the email {

  • 0

I have a JSON of this format with dynamic keys for the email

{
   "id":johnsmith@gmail.com",
   "contact":[
  {
     "uid":0,
     "name":"johnsmith",
     "email":[
        {
           "home":"johnsmith0@gmail.com"
        },
        {
           "work":"johnsmith1@gmail.com"
        }
     ],
     "mobile":[
        {
           "cc":"+60",
           "mobile":"00000000"
        },
        {
           "cc":"+60",
           "mobile":"00000001"
        }
     ]
  }
   ]
}

I tried

Iterator it = contactArray.getJSONObject(i)
            .getJSONObject("email").keys();

But i’m getting an error

org.json.JSONException: JSONObject["email"] is not a JSONObject.

But doing this works, but there is no method to get keys from a JSONArray.

            JSONArray emailArray = contactArray.getJSONObject(i)
                    .getJSONArray("email");

How to handle dynamic keys? Thanks.

  • 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-05-25T17:25:53+00:00Added an answer on May 25, 2026 at 5:25 pm

    Arrays don’t have keys, they have elements. This should be based on a java collection type, use a loop structure to test it:

    JSONArray emailArray = contactArray.getJSONObject(i).getJSONArray("email");
    
    for(Object o: emailArray){
        System.out.println(o);
    }
    

    If the emailArray is empty, nothing will be output, if it has elements in it the value will be output.

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

Sidebar

Related Questions

I have a json data in this format. ({test:[test, <br/><div><b>Name</b>    James;/div><div><b>Company</b>   Company1</div><div><b>Phone.....}). I need to
I have a JSON String in this format: { supplier: { mov_10: love actually,
I have a JSON format like this returned via a ajax call { user_page_id:36,
I have JSON Data in this format : var jsonData = [{date:'August 19, 2004',open:100.01,high:104.06},{date:'August
I have a multidimensional array converted to JSON data in this format. [[null,null,null,null,null,null],[null,null,null,1,1,null],[null,null,null,null,1,1],[null,null,null,null,null,null],[null,null,null,null,null,null]] I
I have json in this format: { minci88: { idUser: 2775040, nick: minci88, photo:
I have a JSON feed that drupal spits out time in this format: 2010-12-16T04:41:35Z
I have json in format like this: {0:{title:\u0417\u041d: \u0415\u0432\u0440\u043e\ ... How to encode \uxxxx
I have a JSON result in the following format which JSON Lint shows this
Am new to jquery. Have json response from php in this format. { div1:{data:minute=0,hour=27,day=649,month=19K,smallSize=0,

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.