Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-20-2010, 03:48 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 204
marciokoko is on a distinguished road
Question iOS json php

Ive got a php page reading a mysql db and encoding $json result of the db query. I am using a modified version of the TwitterHelper class used in Presence assignment of CS193P btw. Here is the relevant code:

<?php

include_once("JSON.php");
$json = new Services_JSON();

$link = mysql_pconnect("localhost", "user", "paas") or die("Could not connect");
mysql_select_db("iglobe") or die("Could not select database");

$query = "SELECT * FROM tags";

$arr = array();
$rs = mysql_query("SELECT * FROM tags");

while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}
Echo $json->encode($arr);
?>

and the iOS code is this:

userDict = [[NSDictionary alloc] initWithDictionary:[SantiappsHelper fetchInfoForUDID:@"1"]];

which calls:

+ (NSDictionary*)fetchInfoForUDIDNSString *)udid{
NSString *urlString = [NSString stringWithFormat:@"http://www.server.com/app/getusers.php"];
NSLog(@"This is the urlString from (fetchInfoForUDID) SantiappsHelper:%@",urlString);
NSURL *url = [NSURL URLWithString:urlString];
return [self fetchJSONValueForURL:url];
}

which in turn calls this:

+ (id)fetchJSONValueForURLNSURL *)url{
NSString *jsonString = [[NSString alloc] initWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];

id jsonValue = [jsonString JSONValue];
NSLog(@"This is the string presented:%@",jsonString);
[jsonString release];

return jsonValue;
NSLog(@"returned jsonvalue, going back to tlvc");
}

The app crashes because im getting the php data in this format:

[
{"id":"1","name":"user","pass":"","udid":"269d40ba 6575b9ec51a7f3237e757c2bcd6bf6","timestamp":"0000-00-00 00:00:00","reglocation":""},
{"id":"2","name":"other","pass":"","udid":"2031aaf b778b3a27635ae38e4315f31bba956805","timestamp":"00 00-00-00 00:00:00","reglocation":""},
{"id":"4","name":"hers","pass":"","udid":"F6869 FB4-2EBE-5D43-A62D-5D4007646764","timestamp":"2010-09-18 11:15:16","reglocation":""},
{"id":"5","name":"his","pass":"","udid":"adf03902c 18974c9d29edf27da779afa66438a3b","timestamp":"2010-09-18 11:18:52","reglocation":""}
]

and trying to put it into a dictionary which json string's format should be:


{
"contributors_enabled" = 0;
"created_at" = "Fri Jun 26 19:45:24 +0000 2009";
description = "";
...
}

so how can i change the format of the json data retrieved?
__________________
Mars
www.santiapps.com
www.gea-hn.com
mba-i4

Last edited by marciokoko; 09-20-2010 at 03:50 PM. Reason: pass
marciokoko is offline   Reply With Quote
Old 09-20-2010, 04:30 PM   #2 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 204
marciokoko is on a distinguished road
Question json server?

Quote:
Originally Posted by marciokoko View Post
Ive got a php page reading a mysql db and encoding $json result of the db query. I am using a modified version of the TwitterHelper class used in Presence assignment of CS193P btw. Here is the relevant code:

<?php

include_once("JSON.php");
$json = new Services_JSON();

$link = mysql_pconnect("localhost", "user", "paas") or die("Could not connect");
mysql_select_db("iglobe") or die("Could not select database");

$query = "SELECT * FROM tags";

$arr = array();
$rs = mysql_query("SELECT * FROM tags");

while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}
Echo $json->encode($arr);
?>

and the iOS code is this:

userDict = [[NSDictionary alloc] initWithDictionary:[SantiappsHelper fetchInfoForUDID:@"1"]];

which calls:

+ (NSDictionary*)fetchInfoForUDIDNSString *)udid{
NSString *urlString = [NSString stringWithFormat:@"http://www.server.com/app/getusers.php"];
NSLog(@"This is the urlString from (fetchInfoForUDID) SantiappsHelper:%@",urlString);
NSURL *url = [NSURL URLWithString:urlString];
return [self fetchJSONValueForURL:url];
}

which in turn calls this:

+ (id)fetchJSONValueForURLNSURL *)url{
NSString *jsonString = [[NSString alloc] initWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];

id jsonValue = [jsonString JSONValue];
NSLog(@"This is the string presented:%@",jsonString);
[jsonString release];

return jsonValue;
NSLog(@"returned jsonvalue, going back to tlvc");
}

The app crashes because im getting the php data in this format:

[
{"id":"1","name":"user","pass":"","udid":"269d40ba 6575b9ec51a7f3237e757c2bcd6bf6","timestamp":"0000-00-00 00:00:00","reglocation":""},
{"id":"2","name":"other","pass":"","udid":"2031aaf b778b3a27635ae38e4315f31bba956805","timestamp":"00 00-00-00 00:00:00","reglocation":""},
{"id":"4","name":"hers","pass":"","udid":"F6869 FB4-2EBE-5D43-A62D-5D4007646764","timestamp":"2010-09-18 11:15:16","reglocation":""},
{"id":"5","name":"his","pass":"","udid":"adf03902c 18974c9d29edf27da779afa66438a3b","timestamp":"2010-09-18 11:18:52","reglocation":""}
]

and trying to put it into a dictionary which json string's format should be:


{
"contributors_enabled" = 0;
"created_at" = "Fri Jun 26 19:45:24 +0000 2009";
description = "";
...
}

so how can i change the format of the json data retrieved?
----------------

i just realized the TwitterHelper class file uses this format:

@"http://www.twitter.com/statuses/user_timeline/%@.json"

where the %@ is the username passed to it...so does this mean there is a special webpage created for every user when the request is made? Does this mean i would need a special server to server .json pages created dynamically from my php-mysql code?
__________________
Mars
www.santiapps.com
www.gea-hn.com
mba-i4
marciokoko is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 317
13 members and 304 guests
2ndSegment, cayladv57, cgokey, djohnson, Domele, Hamad, linkmx, markuschow, mistergreen2011, pungs, Sloshmonster, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:02 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0