ios - Accessing JSON elements in PHP -
php noob here. building iphone app sending json blobs web server. on server side receiving json , trying access 3 fields object contains.
two weird things happening me not figure out how fix:
- i not getting when printing out decoded object($post_data below).
- i able print full object in xcode when printing object without decoding ($content below) have no idea how access various fields in object.
my php code:
$con = mysql_connect("127.0.0.1","root", "") or die('could not connect: ' . mysql_error()); $content = file_get_contents('php://input'); $post_data = json_decode($content , true); echo $content; --> prints object echo $post_data; --> not print echo $content->lat; --> not print
my json object:
{ "lat" : 37.33233141, "long" : -122.0312186, "speed" : 0 }
any appreciated.
it's because json_decode($content, true)
returning array, has problems displaying if echo container.
try doing echo $post_data['lat'];
you can try using print_r($post_data);
have output actual contents of variable can see if isn't working properly
Comments
Post a Comment