I am currently using a really inefficient way of retrieving data from mysql. I wrote very small script to test the functionality (I am very new to ios development). Here is the end of the script which is my main concern:
$fp = fopen('results.json', 'w');
fwrite($fp, json_encode($articles));
fclose($fp);
so i change my results from query to json and then write it to file with .json so that I read it using objective-c. it works but I can see this being a problem (every time creating files and deleting them when querying the database). This is the ios end of things:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData* data = [NSData dataWithContentsOfURL:
[NSURL URLWithString: @"http://link/results.json"]];
NSError* error;
eventsArray = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:&error];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
});
How can I make my php script return json instead of writing it to file and then just read that with objective-c? I am interested in obj-c part so please emphasise as much as possible.
greatly appreciated :D
Does echo json_encode($articles); help you?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.