VOOZH about

URL: https://www.digitalocean.com/community/tutorials/android-jsonobject-json-parsing?comment=186007

⇱ Android JSONObject - JSON Parsing in Android | DigitalOcean


Android JSONObject - JSON Parsing in Android

Published on August 4, 2022

By Anupam Chugh

👁 Android JSONObject - JSON Parsing in Android

Android JSONObject is used for JSON parsing in android apps. In this tutorial we’ll discuss and implement a JSONObject in our android application to parse JSON data. JSON stands for JavaScript Object Notation.

What is JSON?

JSON is used for data interchange (posting and retrieving) from the server. Hence knowing the syntax and it’s usability is important. JSON is the best alternative for XML and its more readable by human. JSON is language independent. Because of language in-dependency we can program JSON in any language (Java/C/C++). A JSON response from the server consists of many fields. An example JSON response/data is given below. We’ll use it as a reference and implement it in our application.

{
 "title":"JSONParserTutorial",
 "array":[
 {
 "company":"Google"
 },
 {
 "company":"Facebook"
 },
 {
 "company":"LinkedIn"
 },
 {
 "company" : "Microsoft"
 },
 {
 "company": "Apple"
 }
 ],
 "nested":{
 "flag": true,
 "random_number":1
 }
}

We’ve create a random JSON data string from this page. It’s handy for editing JSON data. A JSON data consists of 4 major components that are listed below:

  1. Array: A JSONArray is enclosed in square brackets ([). It contains a set of objects
  2. Object: Data enclosed in curly brackets ({) is a single JSONObject. Nested JSONObjects are possible and are very commonly used
  3. Keys: Every JSONObject has a key string that’s contains certain value
  4. Value: Every key has a single value that can be of any type string, double, integer, boolean etc

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the author

👁 Anupam Chugh
Anupam Chugh
Author
Category:
Tags:
While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.

Still looking for an answer?

Was this helpful?

Woow man…Your teaching style is so cool…I am totally impressed…Carry on… Thank You…

- shihab

I really love ur all tutorials, But sorry to say this1 is not that upto the mark. You could have shown it with how to get json data from url…using HTTPHandler Also asynctask can be used in this. If possible can you update your this tutorial accordingly. (Just a suggestion) Thanks

- khushbu

Simple and to the point, Helpful article.

- basic

Hi, can you please tell me how would you parse this JSON in Android Studio" { “Article”:[ { “InvDepartmentId”:“001000000000012”, “InvDepartmentName”:“mens”, “InvCategoryId”:“001000000000023”, “InvCategoryName”:“adult”, “InvSubCategoryId”:“001000000000021”, “InvSubCategoryName”:“abc”, “ArticleId”:“001000000000186”, “ArticleNo”:“test22246”, “ArticleWSP”:1100.00, “CreatedOn”:“2018-09-14T12:51:04”, “LastUpdate”:“2018-09-14T12:51:30.823” } I have written this code until now: StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener() { @Override public void onResponse(String response) { try { JSONObject js = new JSONObject(response); JSONArray jsonArray = js.getJSONArray(Constants.Article); String InvDepartmentId = jsonArray.getString(Integer.parseInt(“InvDepartmentId”)); String InvDepartmentName = jsonArray.getString(Integer.parseInt(“InvDepartmentName”)); String InvCategoryId = jsonArray.getString(Integer.parseInt(“InvCategoryId”)); Help would be highly appreciated.Thanks !

- Akansha Rattan

json parsing of object or array of only numbers i try to find it everywhere not a single solution as take it as a challenge and pls help me.

- keshav

How to get value for radio Button in json through two value jobseeker & jobprovider plz help me

- Dhara Dadhaniya

how to parse this type of data::: { “status”: true, “msg”: “Main type found successfully.”, “data”: [ { “id”: 8, “name”: “Music”, “created_at”: “2020-12-11T11:14:12.000000Z”, “updated_at”: “2020-11-07T05:28:30.000000Z”, “images”: [ { “id”: 6, “category_id”: 8, “aws_s3_key”: “category/c9f0f895fb98ab9159f51fd0297e236d/160474961147830.jpg”, “media_url”: “https://ehs-media-development.s3.ap-south-1.amazonaws.com/category/c9f0f895fb98ab9159f51fd0297e236d/160474961147830.jpg”, “created_at”: “2020-11-07T06:16:53.000000Z”, “updated_at”: “2020-11-07T06:16:53.000000Z” } ] }, { “id”: 9, “name”: “Art”, “created_at”: “2020-12-11T11:14:21.000000Z”, “updated_at”: “2020-12-08T05:02:53.000000Z”, “images”: [ { “id”: 7, “category_id”: 9, “aws_s3_key”: “category/c9f0f895fb98ab9159f51fd0297e236d/160474961147830.jpg”, “media_url”: “https://ehs-media-development.s3.ap-south-1.amazonaws.com/teacher\_portfolio\_image/e4da3b7fbbce2345d7772b0674a318d5/160766398952238.jpg”, “created_at”: “2020-12-11T11:16:26.000000Z”, “updated_at”: “2020-11-07T06:16:53.000000Z” } ] } ] }

- Devendra Aparnathi

how to retrive data from database table using JSON parser library

- zig girma

👁 Creative Commons
This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.
  • Deploy on DigitalOcean

    Click below to sign up for DigitalOcean's virtual machines, Databases, and AIML products.

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and AI-native businesses

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

© 2026 DigitalOcean, LLC.Sitemap.
Dark mode is coming soon.