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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:23:42+00:00 2026-06-05T20:23:42+00:00

I have used following code to convert string to json and parse it. String

  • 0

I have used following code to convert string to json and parse it.

String sb= {"meta": {"limit": 20, "next": null, "offset": 0, "previous": null, "total_count": 1}, "objects": [{"api_key": "c87391754b522d0c83b2c8b5e4c8cfd614559632deee70fdf1b48d470307e40e", "homeAddress": "kathmandu", "resource_uri": "/api/ca/entry/1/", "username": "sumit"}]}
    try {

                    JSONObject jsonObject = new JSONObject(sb);
                    JSONObject object = jsonObject.getJSONObject("objects");  
                    String api_key= object.getString("api_key");  
                    Toast.makeText(HelloWorldActivity.this, api_key, Toast.LENGTH_SHORT).show();

        } catch (JSONException e) {
                             e.printStackTrace();
                            }

Following some tutorials i tried to parse the json, but i am not able to parse it. for example : i want to return api_key as c87391754b522d0c83b2c8b5e4c8cfd614559632deee70fdf1b48d470307e40e

any thing that i have mistaken in above code

  • 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-05T20:23:43+00:00Added an answer on June 5, 2026 at 8:23 pm

    Always use JSONLint or similar sites to well format your JSON.

    Your JSON is like this

    {
        "meta": {
            "limit": 20,
            "next": null,
            "offset": 0,
            "previous": null,
            "total_count": 1
        },
        "objects": [
            {
                "api_key": "c87391754b522d0c83b2c8b5e4c8cfd614559632deee70fdf1b48d470307e40e",
                "homeAddress": "kathmandu",
                "resource_uri": "/api/ca/entry/1/",
                "username": "sumit"
            }
        ]
    }
    

    here “objects” will return array not object.

    Change you code to following.

        try {
    
                JSONObject jsonObject = new JSONObject(sb);
                JSONArray array = jsonObject.getJSONArray("objects");
    
                String key = array.getJSONObject(0).getString("api_key");
                String uname = array.getJSONObject(0).getString("username");
                Toast.makeText(HelloWorldActivity.this, username + " " + key,
                        Toast.LENGTH_SHORT).show();
    
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have never used Foxpro before. Can you convert the following Foxpro code into
I have used the following code to set cookie and then redirect. String level=(String)
I want to directly convert a javascript object to string. I used following code.
I have the following code to convert a string to char : string tempLine
I used the following piece of code to retrieve basically a JSON formatted String
i have used following code to repeat a process creation/close iteratively dim vProcessInfo as
I have used following code to create a simple PDF file. It executes fine
I have used the following code to pick up an image from phone's gallery:
I have used the following code in a number of applications to load .DLL
i have used the following code in .htaccess Options +FollowSymlinks RewriteEngine On RewriteBase /

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.