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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:28:18+00:00 2026-05-24T00:28:18+00:00

Hello friends i am having problem in parsing jSON web services data I have

  • 0

Hello friends i am having problem in parsing jSON web services data

I have the following set of data i got from my web services

[{"store_id":"81","store_name":"Mayo - Castlebar McDrive","store_type":"Drive-Thru",
"vouchers_available":"Vouchers available","store_limit":"10","distance":"8123.33 km",
"latitude":"53.8501090162671","longitude":"-9.29713726043701","image_name":"http:\/\/www.mcfinder.ie\/admin\/images\/stores\/default.png",
"voucher_count":"2","is_open":"Restaurant Open","attributes":[{"attribute_name":"Wi-Fiiiii",
"image_name":"http:\/\/www.mcfinder.ie\/admin\/images\/attributes\/t_wifi_icon.gif"},{"attribute_name":"Cashless",
"image_name":"http:\/\/www.mcfinder.ie\/admin\/images\/attributes\/t_cashless_icon.gif"},
{"attribute_name":"McDrive","image_name":"http:\/\/www.mcfinder.ie\/admin\/images\/attributes\/car_icon.png"}]}]

and i m using this code to parse the DATA but i am getting the error

Please friends i am new in JSON Web services guide me what am i doing wrong.

CODE:

JSONObject jObject = new JSONObject(data);
JSONArray array = jObject.getJSONArray("attributes");

ERROR:

07-19 23:43:02.437: WARN/System.err(674): org.json.JSONException: A JSONObject text must begin with '{' at character 2 of 

M waiting for some positive response and guidelines

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-05-24T00:28:19+00:00Added an answer on May 24, 2026 at 12:28 am

    If you’re going to work with JSON data, I recommend reviewing the JSON introduction at http://json.org, until it is thoroughly understood. Luckily, JSON is a relatively simple data format, and becoming comfortable with it comes quickly.

    To the specific problem in the original question, note that the outer-most structure of the JSON data is an array. So, it needs to be read as an array — not as an object.

    Here’s a brief description of the complete JSON structure.

    An array with one element that is an unnamed object. The unnamed object has twelve elements, eleven of which are strings, and one of which, named “attributes”, is an array of three objects. Each object in the “attributes” array has two string elements.

    So, if you want the “attributes” array, first read in the entire contents as an array, then get the first component of the array as an object, then get the “attributes” element from that object as an array. Following is an example of doing this.

    import java.math.BigDecimal;
    import java.net.URI;
    import java.util.List;
    
    import org.json.JSONArray;
    import org.json.JSONObject;
    
    public class Foo
    {
      public static void main(String[] args) throws Exception
      {
        JSONArray outerArray = new JSONArray("[{\"store_id\":\"81\",\"store_name\":\"Mayo - Castlebar McDrive\",\"store_type\":\"Drive-Thru\",\"vouchers_available\":\"Vouchers available\",\"store_limit\":\"10\",\"distance\":\"8123.33 km\",\"latitude\":\"53.8501090162671\",\"longitude\":\"-9.29713726043701\",\"image_name\":\"http:\\/\\/www.mcfinder.ie\\/admin\\/images\\/stores\\/default.png\",\"voucher_count\":\"2\",\"is_open\":\"Restaurant Open\",\"attributes\":[{\"attribute_name\":\"Wi-Fiiiii\",\"image_name\":\"http:\\/\\/www.mcfinder.ie\\/admin\\/images\\/attributes\\/t_wifi_icon.gif\"},{\"attribute_name\":\"Cashless\",\"image_name\":\"http:\\/\\/www.mcfinder.ie\\/admin\\/images\\/attributes\\/t_cashless_icon.gif\"},{\"attribute_name\":\"McDrive\",\"image_name\":\"http:\\/\\/www.mcfinder.ie\\/admin\\/images\\/attributes\\/car_icon.png\"}]}]");
        JSONObject object = outerArray.getJSONObject(0);
        JSONArray attributes = object.getJSONArray("attributes");
        for (int i = 0, length = attributes.length(); i < length; i++)
        {
          JSONObject attribute = attributes.getJSONObject(i);
          System.out.printf("attribute name=%s, image=%s\n", attribute.getString("attribute_name"), attribute.getString("image_name"));
        }
      }
    }
    

    If you’re not stuck using the built-in JSON API that Android provides, I highly recommend switching to Jackson, which makes it very easy to read and write arbitrarily complex JSON with Java. Following is an example of using it.

    import java.io.File;
    import java.math.BigDecimal;
    import java.net.URI;
    import java.util.List;
    
    import org.codehaus.jackson.map.ObjectMapper;
    
    public class Foo
    {
      public static void main(String[] args) throws Exception
      {
        ObjectMapper mapper = new ObjectMapper();
        Store[] stores = mapper.readValue(new File("input.json"), Store[].class);
        Store store = stores[0];
        List<Attribute> attributes = store.attributes;
        for (Attribute attribute : attributes)
        {
          System.out.printf("attribute name=%s, image=%s\n", attribute.attribute_name, attribute.image_name);
        }
        // output:
        // attribute name=Wi-Fiiiii, image=http://www.mcfinder.ie/admin/images/attributes/t_wifi_icon.gif
        // attribute name=Cashless, image=http://www.mcfinder.ie/admin/images/attributes/t_cashless_icon.gif
        // attribute name=McDrive, image=http://www.mcfinder.ie/admin/images/attributes/car_icon.png
      }
    }
    
    class Store
    {
      public String store_id;
      public String store_name;
      public String store_type;
      public String vouchers_available;
      public String store_limit;
      public String distance;
      public BigDecimal latitude;
      public BigDecimal longitude;
      public URI image_name;
      public int voucher_count;
      public String is_open;
      public List<Attribute> attributes;
    }
    
    class Attribute
    {
      public String attribute_name;
      public URI image_name;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello friends I have the following script in my Template: window.addEvent('domready', function () {
hello friends in my project i have an arraylist showing results in a jsp
Hello friends I have an issue adding a special class to a couple of
Hello friends a newbie question... The Issue is like this: I have a static
Hello Friends I want to upload a image but according to requirement when click
Hello Friends I am a newbie programmer and very very new to PHP. I
Hello friends I am running 2 applications on the same server and I wanted
Hello friends I am trying to add a class to body dynamically depending on
I am having a strange linking error. I followed instructions presented here to avoid
Hello everyone in stackoverflow land, A while back I did a website for a

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.