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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:07:03+00:00 2026-06-03T05:07:03+00:00

I want to convert JSON into java code. My jsoncode as per given below.

  • 0

I want to convert JSON into java code. My jsoncode as per given below.

{
"nodes": [
    {
        "node": {
            "Name": "rahul Patel",
            "Address": "\n\tAhmedabad",
            "Date of Birth": "1991-05-03",
            "Occupation": "developer",
            "Member Since": "3 weeks 4 days"
        }
    }
]

java code

try {
            JSONObject objResponse = new JSONObject(strResponse);

            JSONArray jsonnodes = objResponse
                    .getJSONArray(nodes);


            System.out.println("=hello this is DoinBackground");
            for (i = 0; i < jsonnodes.length(); i++) {

                System.out.println("hello this is for loop of DoinBackground");
                JSONObject jsonnode = jsonnodes.getJSONObject(i);

                JSONObject jsonnodevalue = jsonnode
                        .getJSONObject(node);

                bean = new UserProfileBean();

                bean.name = jsonnodevalue.getString(Name);


                listActivities.add(bean);

            }
        } catch (JSONException e) {

            e.printStackTrace();
        }
}

Here in logcat I print the value of before for loop System.out.println("=hello this is DoinBackground");,but value can’t print under the for loop System.out.println("hello this is for loop of DoinBackground");

NOTE: Please let me know, Is it possible that we cannot used for loop in the code ? if yes then give the solution for that, There is another solution for this given problem.

Thanks.

  • 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-03T05:07:04+00:00Added an answer on June 3, 2026 at 5:07 am

    Your json string is wrong. It must be trminated with }. Fix this and it will work.

    Fixed json string:

    {
        "nodes": [
            {
                "node": {
                    "Name": "rahul Patel",
                    "Address": "\n\tAhmedabad",
                    "Date of Birth": "1991-05-03",
                    "Occupation": "developer",
                    "Member Since": "3 weeks 4 days"
                }
            }
        ]
    }
    

    Sample code to test:

    String j = "{\r\n" + 
            "    \"nodes\": [\r\n" + 
            "        {\r\n" + 
            "            \"node\": {\r\n" + 
            "                \"Name\": \"rahul Patel\",\r\n" + 
            "                \"Address\": \"\\n\\tAhmedabad\",\r\n" + 
            "                \"Date of Birth\": \"1991-05-03\",\r\n" + 
            "                \"Occupation\": \"developer\",\r\n" + 
            "                \"Member Since\": \"3 weeks 4 days\"\r\n" + 
            "            }\r\n" + 
            "        }\r\n" + 
            "    ]\r\n" + 
            "}";
    
    try{
        JSONObject objResponse = new JSONObject(j);
    
        JSONArray jsonnodes = objResponse.getJSONArray("nodes" );
    
        for (int i = 0; i < jsonnodes.length(); i++) {
    
            JSONObject jsonnode = jsonnodes.getJSONObject(i);
    
            JSONObject jsonnodevalue = jsonnode
                    .getJSONObject("node");
    
            Log.v("name", jsonnodevalue.getString("Name"));
            Log.v("address", jsonnodevalue.getString("Address"));
            Log.v("occupation", jsonnodevalue.getString("Occupation"));
        }
    
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to convert the following json and put the values into a data
I have an XML file which I want to convert into JSON file using
I want to convert the output of ifstat command into JSON and serve it
i have a json array that i want to convert into a plain javascript
I want to convert .json file into .csv file using ruby. Pleases help me
I want to be able to convert a List<T> into a specific JSON table-like
i have some json data, and i want to convert it into plain text,
I want to convert this linear loop into a concurrent one: for(Item item :
I want to convert a binary file into an array of ascii charcters .
I want to convert all texts in a string into html entities but preserving

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.