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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:55:27+00:00 2026-06-18T09:55:27+00:00

My JSON output in PHP is done this way: print json_encode(array(‘rate’ => $topcat, ‘hometown’

  • 0

My JSON output in PHP is done this way:

 print json_encode(array('rate' => $topcat, 'hometown' => $hometown, 'talk' => $talk));

My JSON output looks like this in my browser:

{“rate”:”Movies”,”hometown”:”Seattle, WA”,”talk”:”Movies”}

in Java/Android I do this:

protected void onPostExecute(Void v) {

    try {
        JSONArray jArray = new JSONArray(result);
        JSONObject json_data = null;
        for (int i = 0; i < jArray.length(); i++) {
            json_data = jArray.getJSONObject(i);


            Hometown = json_data.getString("hometown");
            FavCategory = json_data.getString("rate");              
            Talk = json_data.getString("talk");



        }
    } catch (JSONException e1) {

    } catch (ParseException e1) {
        e1.printStackTrace();
    }

    if (Hometown.equals("")) {
        Hometown = "Not Specified";
    }

    tvHometown.setText(Hometown);
    tvRate.setText(FavCategory);
    tvTalk.setText(Talk);

    Log.d("Log: ", Hometown + " " + FavCategory + " " + Talk);

}

}

On that Log, I get this: Seattle, WA, null, null

Can anyone see why?

EDIT: New Java Code, still getting error:

String homeTown = "", favCategory = "", favTalk = "";
        try {
            JSONObject jsonData = new JSONObject(result);

            homeTown = jsonData.getString("hometown");
            favCategory = jsonData.getString("rate");
            favTalk = jsonData.getString("talk");


            tvHometown.setText(homeTown);
            tvRate.setText(favCategory);
            tvTalk.setText(favTalk);




} catch (JSONException e1) {

    } catch (ParseException e1) {
        e1.printStackTrace();
    }

I am getting an exception:

02-05 08:51:48.078: E/log_tag(22958): Error in http connection org.json.JSONException: Value null of type org.json.JSONObject$1 cannot be converted to JSONArray
  • 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-18T09:55:28+00:00Added an answer on June 18, 2026 at 9:55 am

    Despite the PHP vocabulary, the top-level element of this JSON:

    {"rate":"Movies","hometown":"Seattle, WA","talk":"Movies"}
    

    is an object (a key-value mapping), not an array. The {}s are a dead giveaway.

    Change this

    JSONArray jArray = new JSONArray(result);
    

    to this:

    JSONObject jsonData = new JSONObject(result);
    

    and go from there:

    String hometown = jsonData.getString("hometown");
    String favCategory = jsonData.getString("rate");              
    String talk = jsonData.getString("talk");
    

    Note how, as a matter of good Java style, I use lowerCamelCased variable names.

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

Sidebar

Related Questions

Why does this output a 0 byte file? <?php $jsonurl = http://do.convertapi.com/Web2Pdf/json/?curl=http://stackoverflow.com/; $json =
Can someone tell me why this alert is empty? var pending_dates = []; $.getJSON('/ajax/event-json-output.php',
Is this the most efficient way to loop through json data and print a
I am using JSON_ENCODE in PHP to output data. When it gets to this
Is it possible to output specific JSON data (exported from Firefox bookmarks) using PHP.
i am outputting json data from a php file (example of my output) {news:[{title:title
I am having this rather long json output in my controller, I wish to
I am trying to create a JSON output with php and when I output
Currently I using the following code to get my JSON output from MySQL. <?php
I have a json output that looks like this.. { XXXX: { name: Dalvin

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.