I have a string that gets it contents from a URL. Im trying to put these contents into an array that will populate a table view. Here is the code I have. What am I doing wrong here? Thanks in advance.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSString *strURL = [NSString stringWithFormat:@"http://10.247.245.87/index.php"];
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
NSArray *nameArray = [[NSArray alloc]initWithContentsOfURL:<#(NSURL *)#>;
return nameArray.count;
}
I believe there are several ways to do this, but here’s a simple way to parse JSON results into arrays. Download the SBJSON framework from here
and add it to your project. Then import the JSON.h file to your
#import "JSON.h". After which you can parse the string into an array using this line of codenameArray = [responseString JSONValue];.#import "JSON.h"nameArray = [responseString JSONValue];Happy Coding!
EDIT:
you can try do something like this to check to see if you have an array of Strings after you parse the JSON into an array:
if the above works out then you can get the strings from the array and fill the tableview in the
cellForRowAtIndexPathdelegate like so: