i want to step into the mySQL, JSON iPhone world. I set up a simple weather station with my Arduino and send the temperature to my MySQL database. I created a php file on my server.
When i open the file in Safari it looks like this:
{"weatherstation":[{"location":"indoor","celsius":"22.85"}]} Now i want to create a simple Application for my iPhone which displays the temperature. Can someone help me out some code? I searched here on stack overflow, but the most people are more advanced than i am.
Almost every code began with:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSURL *url = [NSURL URLWithString:@"http://myWebsite.com/myPHPFile.php"]; NSError *error = nil; I would be very thankful if someone could help me to step into this topic.
EDIT
Here is some code of my php file. how can i change it to a JSON type? i tried it with
header('Content-Type: application/json'); But afterwards my php file shows the whole html structure (< html>...< /html>). do i have to change the html part if i change the content type to json?
<?php ... header('Content-Type: application/json'); ... <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="application/json; charset=utf-8"> <meta name="viewport" content="user-scalable=yes, width=device-width"> <title>My Temperature</title> </head> <body> <?php if(!isset($E)) { ?> {"weatherstation":[{"location":"indoor","celsius":"<?php echo $temp;?>"}]} <?php } else { echo $M; } ?> </body> </html>