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

The Archive Base Latest Questions

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

I am trying to parse a Json response from my webservice. I receive this

  • 0

I am trying to parse a Json response from my webservice. I receive this string from my web server.

{"lon0":"30.13689","lat0":"-96.3331183333333"}{"lon1":"30.136965","lat1":"-96.33252"}{"lon2":"30.1370383333333","lat2":"-96.3319233333333"}

I place it in to a string called jsonStr..
then I place it into an object. And get strings that I need.

JSONObject jsonObj = new JSONObject(jsonStr);//place it into an object
String longitudecord = jsonObj.getString("lon0");//retrieve the lon0
String latitudecord = jsonObj.getString("lat0");

When I try this code above I get the proper longitudecord being 30.13689, and the proper latitudecord being -96.3331183333333.

but when I run this

    String longitudecord = jsonObj.getString("lon1");
String latitudecord = jsonObj.getString("lat1");

I don’t get the correct longitude and latitude. It throws an exception. So I don’t think im trying to get “lon1” and “lat1” correctly.

Can anyone help me with this?

***UPDATE*******
my php code snippet…

    $counter = 0;
// read them back
$result = mysql_query( "SELECT * FROM locations" );
while( $data = mysql_fetch_assoc($result) ) {
$latFromDb = $data['latitude'];
$longFromDb = $data['longitude'];
$variable = array( 'lon'.$counter => "$longFromDb", 'lat'.$counter => "$latFromDb" );
    // One JSON for both variables
echo json_encode($variable);
$counter++;
}

How could I return the proper jSon format

  • 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:47:15+00:00Added an answer on June 3, 2026 at 5:47 am

    It looks like you’re returning 3 separate results. So, some possibilities…

    1. Form the string into a JSONArray, and parse that…

      JSONArray jsonObj = new JSONArray("["+jsonStr.replaceAll("}{","},{")+"]");

      Then iterate through each child of the array to get the lat/long.

    2. Split the returned String into separate result strings, and parse them individually. Maybe something like this…

      String[] results = jsonStr.replaceAll("}{","}}{{").split("}{");

      Note that we replaceAll first so we can keep the } and { at the start/end of each result.


    The better thing would be to fix your PHP server code. You basically just need a [ at the start, an ] at the end, and , between each result. I think something like this might do it (please fix the syntax for me – i’m not a PHP coder).

        $counter = 0;
    // read them back
    $result = mysql_query( "SELECT * FROM locations" );
    echo '[';
    while( $data = mysql_fetch_assoc($result) ) {
    if (&counter >= 1){
      echo ',';
    }
    $latFromDb = $data['latitude'];
    $longFromDb = $data['longitude'];
    $variable = array( 'lon'.$counter => "$longFromDb", 'lat'.$counter => "$latFromDb" );
        // One JSON for both variables
    echo json_encode($variable);
    $counter++;
    }
    echo ']';
    

    Once you’ve got that, you should just be able to say new JSONArray(serverResult) and it’ll parse all of your results into a JSON Array that you can iterate through.

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

Sidebar

Related Questions

I;m trying to parse a json string which I receive from web server as
I am trying to parse a JSON response from a server using javascript/jquery. This
I'm actually trying to parse a JSON request response from my PHP web service
I am trying to parse Json response from This URL . I have used
I am trying to parse the JSON response from Wordnik's API. This is built
I was trying to parse response data from web server. I am using Xcode
I'm trying to parse JSON with jQuery I get from a remote server through
I'm trying to fetch information from a JSON web service with this code, using
I am trying to parse a response from server and i am new to
I am trying to parse JSON response from a httpwebrequest fetch and a little

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.