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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:49:32+00:00 2026-06-02T04:49:32+00:00

I am building one app in which I request a PHP file from server.

  • 0

I am building one app in which I request a PHP file from server. This PHP file returns a JSONArray having JSONObjects as its elements e.g.,

[ 
  {
    "uniqid":"h5Wtd", 
    "name":"Test_1", 
    "address":"tst", 
    "email":"ru_tst@tst.cc", 
    "mobile":"12345",
    "city":"ind"
  },
  {...},
  {...},
  ...
]

my code:

/* jArrayFavFans is the JSONArray i build from string i get from response.
   its giving me correct JSONArray */
JSONArray jArrayFavFans=new JSONArray(serverRespons);
for (int j = 0; j < jArrayFavFans.length(); j++) {
  try {
    if (jArrayFavFans.getJSONObject(j).getString("uniqid").equals(id_fav_remov)) {
      //jArrayFavFans.getJSONObject(j).remove(j); //$ I try this to remove element at the current index... But remove doesn't work here ???? $
      //int index=jArrayFavFans.getInt(j);
      Toast.makeText(getParent(), "Object to remove...!" + id_fav_remov, Toast.LENGTH_SHORT).show();
    }
  } catch (JSONException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
}

How do I remove a specific element from this JSONArray?

  • 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-02T04:49:34+00:00Added an answer on June 2, 2026 at 4:49 am

    Try this code

    ArrayList<String> list = new ArrayList<String>();     
    JSONArray jsonArray = (JSONArray)jsonObject; 
    
    if (jsonArray != null) { 
       int len = jsonArray.length();
       for (int i=0;i<len;i++){ 
        list.add(jsonArray.get(i).toString());
       } 
    }
    //Remove the element from arraylist
    list.remove(position);
    //Recreate JSON Array
    JSONArray jsArray = new JSONArray(list);
    

    Edit:
    Using ArrayList will add "\" to the key and values. So, use JSONArray itself

    JSONArray list = new JSONArray();     
    JSONArray jsonArray = new JSONArray(jsonstring); 
    int len = jsonArray.length();
    if (jsonArray != null) { 
       for (int i=0;i<len;i++)
       { 
           //Excluding the item at position
            if (i != position) 
            {
                list.put(jsonArray.get(i));
            }
       } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building one app having one list view showing list of users this
I am building an app which contains a form in one view,in which the
I am building an Android app which takes a string input and returns a
I'm building an app that uses a TabBar controller in which one of the
I'm building a JSF+Facelets web app, one piece of which is a method that
I am building a Prism app with several modules, one of which ( MyModule
I'm building an app which receives a number of listings from a web API,
So I am building an app which have a File Transfer application which allows
How does one approach building the mobile app version of one's Rails app, with
I'm building a WPF app using pages and the navigation service. One of the

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.