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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:08:17+00:00 2026-05-30T05:08:17+00:00

I followed Ray Wenderlich’s tutorial on creating a web service / hooking it up

  • 0

I followed Ray Wenderlich’s tutorial on creating a web service / hooking it up to iOS but his example the returned results only have one possible row returned in the query. I’d like to return all possible results in a JSON format but I am confused how to store them as the correct key.

Here’s what I have for the PHP:

$stmt = $this->db->prepare('SELECT userID, lat, lng FROM Connections WHERE airline=? AND flight_number=? ');
$stmt->bind_param("si", $airline, $flight_number);
$stmt->execute();
$stmt->bind_result($otherUser, $otherLat, $otherLng);
    while ($stmt->fetch()) {
        break;
    }
 $stmt->close();

if ($otherUser) {
        //sendResponse(403, 'Code already used');
        //return false;
        $myLatLng = "$lat,$long";
        $otherLatLng="$otherLat,$otherLng";
        $results = getDistanceBetween($myLatLng,$otherLatLng);
        $miles = $results[0];
        $minutes = $results[1];
        $result = array(
                "other_user" => $otherUser,
                "distance" => $miles,
                "duration" => $minutes,

                );
        sendResponse(200, json_encode($result));
        return true;
    }

On the Obj-C side of things I get these values using this code:

 if (request.responseStatusCode == 200) {
    NSString *responseString = [request responseString];
    NSDictionary *responseDict = [responseString JSONValue];
    NSString *otherUser = [responseDict objectForKey:@"other_user"];
    NSString *otherDistance = [responseDict objectForKey:@"distance"];
    NSString *otherDuration = [responseDict objectForKey:@"duration"];

Can someone please help me out?

  • 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-30T05:08:18+00:00Added an answer on May 30, 2026 at 5:08 am

    In your PHP code you want to create a nested array and then use json_encode(). Here is a previous question with more detail about the PHP side of your problem: How to create an array for JSON using PHP?

    On the iOS side, since your webservice will return a JSON response representing multiple items, calling JSONValue on the response string will return an NSArray object instead of an NSDictionary. You can then iterate over the items in the array (which will themselves be NSDictionary items) and pull out the values you need.

    NSString *responseString = [request responseString];
    NSArray *responseArray = [responseString JSONValue];
    
    for (NSDictionary* item in responseArray) {
        NSString *otherUser = [item objectForKey:@"other_user"];
        NSString *otherDistance = [item objectForKey:@"distance"];
        NSString *otherDuration = [item objectForKey:@"duration"];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I followed Ray Wenderlich's tutorial on text autocompletion here: http://www.raywenderlich.com/336/how-to-auto-complete-with-custom-values And it works great,
I followed the example at http://blog.hivedevelopment.co.uk/2009/08/google-web-toolkit-gwt-mvp-example.html and built the example GWT application, but then
I recently followed Ray Wenderlich's Cocos2D tutorial for putting Cocos2D in a UIKit app.
I followed the RailsCasts tutorial to do a simple search with autocomplete, but it
I followed this tutorial but still I go to the webpage refresh, then go
I followed the example SSO on Facebook's developer website but am getting a strange
I followed the HelloWorld module tutorial on Orchard's website, but I didn't really see
I followed the example http://www.dealtaker.com/blog/2010/02/25/kohana-php-3-0-ko3-tutorial-part-5/ I get the following error: ErrorException [ Notice ]:
I followed the official Authlogic tutorial but something came up. I successfully created a
I followed this article: Effective NHibernate Session management for web apps But this: public

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.