PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 11, 2022

[FIXED] How to get specific data from JSON OR URL in Android?

 October 11, 2022     android, json, phpmyadmin     No comments   

Issue

I want to get particular user data from PHP MySql in Android. Here is my URL (xxx//xxxxxxx/client_vendor_mgmt/subcategory.php?cat_id=2) and here is the URL data in json:

[
    {
        "subcat_id": "1",
        "subcat_code": "cell1",
        "subcat_name": "cell",
        "cat_id": "2",
        "subcat_created_date": "0000-00-00",
        "subcat_isactive": "Y",
        "subcat_updated_date": "0000-00-00"
    },
    {
        "subcat_id": "2",
        "subcat_code": "cell2",
        "subcat_name": "tv",
        "cat_id": "2",
        "subcat_created_date": "0000-00-00",
        "subcat_isactive": "Y",
        "subcat_updated_date": "0000-00-00"
    }
]

I want to get all the record of "cat_id":"2". How can I get this record?


Solution

Here is the code

try {
            JSONArray array=new JSONArray("yourJsonString");

            JSONArray sortedArray = new JSONArray();
            for(int i=0;i<array.length();i++)
            {
                JSONObject obj=array.getJSONObject(i);
                if(obj.getString("cat_id").equalsIgnoreCase("2"))
                {
                    sortedArray.put(obj);
                }
            }

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


Answered By - Rohan Pawar
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing