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

  • Home
  • SEARCH
  • 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 8552135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:21:21+00:00 2026-06-11T14:21:21+00:00

i am unable to parse data from server using json i am getting data

  • 0

i am unable to parse data from server using json i am getting data in this format.

[{"school":"abc","event":"test","eventdate":"09\/18\/2012","eventtext":"Hello,this is test "}][{"school":"abc","event":"test","eventdate":"09\/18\/2012","eventtext":"Hello,this is test "},{"school":"abc","event":"new test","eventdate":"09\/20\/2012","eventtext":"Hello, test2"}]

I am new to json parsing here’s my code below:

import java.util.ArrayList;
import java.util.HashMap;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONObject;

import android.app.Activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.widget.BaseAdapter;
import android.widget.ListView;

import android.widget.TextView;
import com.appforschools.R;
import com.appforschools.event.Myadapter;

public class event extends Activity {
ListView list;

ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
 @Override

 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.event);
   list=(ListView)findViewById(R.id.listView1);

   try {
        HttpClient client = new DefaultHttpClient();
        HttpGet get = new HttpGet(
                "http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
        HttpResponse rp = client.execute(get);
        String result = EntityUtils.toString(rp.getEntity());
        System.out.println("----------------------- result: " + result);

        result = "{\"root\": " + result + "}";
        JSONObject root = new JSONObject(result);
        JSONArray sessions = root.getJSONArray("root");
        for(int i=0;i<sessions.length();i++){
            HashMap<String, String> map2 = new HashMap<String, String>();
            JSONObject e = sessions.getJSONObject(i);
            map2.put("text", e.getString("eventtext"));
            map2.put("date", e.getString("eventdate"));
            mylist.add(map2);
        }




    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("----------------------- 1");
list.setAdapter(new Myadapter());

 }
public class Myadapter extends BaseAdapter {

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return mylist.size();
        }

        @Override
        public Object getItem(int arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public long getItemId(int arg0) {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public View getView(final int position, View convertView,
                ViewGroup parent) {
            // TODO Auto-generated method stub
            LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.customlistview,
                    null);
            TextView item = (TextView) convertView
                    .findViewById(R.id.text);
            item.setText(mylist.get(position).get(
                    "text"));
            TextView date = (TextView) convertView
                    .findViewById(R.id.date);
            date.setText(mylist.get(position).get("date"));
            return convertView;
        }


    }


 }

when i debug this code then it gets the result in this string String result = EntityUtils.toString(rp.getEntity()); but after the line JSONObject root = new JSONObject(result); it shows exception.
please help me about this

  • 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-11T14:21:22+00:00Added an answer on June 11, 2026 at 2:21 pm

    because the response is a json array, you should do:

    JSONArray root = new JSONArray(result);
    for(int i=0;i<root.length();i++){
    ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried but i was unable to parse this json object which comes from
I am pulling in data from a JSON file using FBJS AJAX. On of
I'm trying to parse a JSON string using the json library. This code works
I am unable to parse response recieve using Touch XML My response from SOAP
I'm getting the data from sharepoint wbesite using activeItemData = ws.GetListItems(listGUID, activeItemViewGUID, qNode, vNode,
I'm trying to parse JSON with jQuery I get from a remote server through
Error: Unable to read data from the transport connection: A blocking operation was interrupted
I'm getting an Unable to obtain public key for StrongNameKeyPair. exception using Newtonsoft's JsonConvert.SerializeObject
I'm unable to test-run a cssparser that I'd like to use. test.py : from
Hi im getting a error saying that adwhirl cannot parse json response Im trying

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.