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

  • Home
  • SEARCH
  • 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 8455337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:15:42+00:00 2026-06-10T12:15:42+00:00

JSONArray cities = json.getJSONArray(city); With the above code got the following output: { id:1,

  • 0
JSONArray cities = json.getJSONArray("city");

With the above code got the following output:

{
"id":"1",
"name":"London"
"country":"United Kingdom"
},

{
"id":"2",
"name":"Madrid"
"country":"Spain"
},

{"id":"3",
"name":"Paris"
"country":"France"
},

{
"id":"3",
"name":"Zurich"
"country":"Switzerland"
}

How can I get only the name from the JSON array to a string array?

e.g.: String[] s ={"London","Madrid","Paris","Zurich"}

  • 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-10T12:15:44+00:00Added an answer on June 10, 2026 at 12:15 pm

    Loop through the JSONArray and pull out the "name" fields. This is done similarly to your json.getJSONArray("city"); call, only in a loop:

    JSONArray cities = json.getJSONArray("city");
    JSONObject city = null;
    String[] s = new String[cities.length()];
    
    for (int i = 0; i < cities.length(); i++)
    {
        city = cities.getJsonObject(i);
        s[i] = city.get("name");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following example json output form java/jsonsimple. The JSONArray is: [{dd1:{actionType:Dept,collegeID:}},{dd2:{actionType:Dept,collegeID:}}] I'm
Ive got this code: loadData : function(jsonArray) { var id = $(this).attr(id); for(var i
I am trying to add string values in JsonArray and after that create Json
I have a JSON array like below: var jsonArray = [{k1:v1},{k2:v2},{k3:v3},{k4:v4},{k5:v5}] I don't know
Hi I want to create a JSON array. I have tried using: JSONArray jArray
JsonArray-Example: [{ name: table, type: table, reportId: 7, componentId: 12, width: 0, height: 0,
I am trying to create a JSON String in the Android application. JSONArray jArrayFacebookData
I am having problems trying to POST a JSON Array. For my Android code,
import org.json.simple.JSONArray; import org.json.simple.JSONAware; import org.json.simple.JSONObject; import org.json.simple.JSONValue; public class JsonTest implements JSONAware {
I have a piece of code that needs to handle both JSONObject and JSONArray

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.