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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:07:35+00:00 2026-06-05T02:07:35+00:00

When i call server its response is based of json object. Actually, I know

  • 0

When i call server its response is based of json object. Actually, I know how to parse JSON object but this response is strange for me. Server response is:

{"body":"Not Available!","clazz":"SoccerMatchPreview","id":{"inc":-2024241794,"machine":415106952,"new":false,"time":1337861978000,"timeSecond":1337861978},"publishedDate":"2012-06-08 17:00:00 +0100","refKey":"SoccerMatchPreview_4fb897be18be8b87f9117595","title":"Poland vs Greece"}

Those Information that I need are body, publishedDate, refKey and title. The code that i have written based of JSON object is this:

JSONObject jObject = new JSONObject(response);
                    JSONArray contestantObjects = jObject.getJSONArray("id");
                    for(int i=0; i<contestantObjects.length(); i++) {
                        mPreview.setBody(contestantObjects.getJSONObject(i).getString("body").toString());
                        mPreview.setPublishedDate(contestantObjects.getJSONObject(i).getString("publishedDate").toString());
                        mPreview.setRefKey(contestantObjects.getJSONObject(i).getString("refKey").toString());
                        mPreview.setTitle(contestantObjects.getJSONObject(i).getString("title").toString());
                    }

But because it doesn’t have “[]” I think it’s not JSON object. therefore, I wrote another code based JSON array.

JSONArray contestantObjects = new JSONArray(response);
                    for(int i=0; i<contestantObjects.length(); i++) {
                        mPreview.setBody(contestantObjects.getJSONObject(i).getString("body").toString());
                        mPreview.setPublishedDate(contestantObjects.getJSONObject(i).getString("publishedDate").toString());
                        mPreview.setRefKey(contestantObjects.getJSONObject(i).getString("refKey").toString());
                        mPreview.setTitle(contestantObjects.getJSONObject(i).getString("title").toString());
                    }

but result is same and Logcat shows:

Value {“id”:{“timeSecond”:1337861978,”time”:1337861978000,”new”:false,”machine”:415106952,”inc”:-2024241794},”body”:”Not Available!”,”title”:”Poland vs Greece”,”publishedDate”:”2012-06-08 17:00:00 +0100″,”clazz”:”SoccerMatchPreview”,”refKey”:”SoccerMatchPreview_4fb897be18be8b87f9117595″} of type org.json.JSONObject cannot be converted to JSONArray

any suggestion would be appreciated. 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-05T02:07:36+00:00Added an answer on June 5, 2026 at 2:07 am
    JSONArray contestantObjects = jObject.getJSONArray("id");
    

    Your error is here, id is itself a complex object, not an array.

    "id":{"inc":-2024241794,"machine":415106952,"new":false,"time":1337861978000,"timeSecond":1337861978}
    

    Therefore, after getting the id JSON object, you should be able to get the individual attributes, e.g. inc, machine, new, time, and timeSecond.

    JSONObject idObject = ...getJSONObject("id");
    String machine = idObject.get("machine");
    

    A JSON array data structure would have looked like this: [] signifies an array.

    For example, "Animals":["Pig", "Cat", "Dog"].

    In another example, it can also be an Array of complex objects, "Animals":[{"name":"AAA", "blood":"A"}, {"name":"BBB", "blood":"B"}].

    EDIT: Here is a good JSON visualizer i would recommend.

    http://jsonviewer.stack.hu/

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

please tell me where is problem. i wrote this xpath query but its not
I am sending to the server this call: var Message = {}; Message['islands'] =
How to call a method on a server side from JSON. Below is the
I am trying to call a web service but facing a strange behavior. we
I understand JSON, but not JSONP. Wikipedia's document on JSON is (was) the top
Is it possible to call Server.Execute with a .NET .aspx page from classic ASP?
I want to make an ajax call to server. I need to fetch the
Can I make ComboBox from AjaxToolkit make call to server every time new letter
I have an Activity that makes a remote server call and tries to populate
The following code is a very simple ajax call to server that alerts back

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.