简体   繁体   中英

Need some help accessing JSON Data iPhone

Disclaimer: I'm new to JSON.

I have a website that offers up it's Data in JSON format and I'm in the process of building an iPhone App to access that data. The problem I have is not actually with the app itself but rather the syntax to access some of the JSON data.

I don't have any issue accessing the data in the Post [ ] Section, however I want to access Attachments > Images > wptouch-new-thumbnail > url

I know you usually would access the data with a dot syntax but with everything I have tried I have been unable to select anything outside of the Post[] section.

it's pretty simple I take what I get from the server through posts and add them to NSStrings or UIImage in the case of the images for use in a UITableView.

I have all of that working however I can't seem to access anything under attachments. I tried to make a different NSDictionary for attachments but that did not work.

Again remember I'm very new to JSON / Accessing data within it.

Any help would be appreciated!

Make NSMutableData as jsonMutableData instead of NSMutableString. in connection dedreceiveresponse , initialize jsonMutableData then,

 //Json Connection

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [jsonMutableData appendData:partialData];   
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{

    NSString *jsonData = [[NSString alloc] initWithData:jsonMutableData encoding:NSUTF8StringEncoding];   

    NSDictionary *filesJSON = [jsonData JSONValue];


    NSArray *files = [filesJSON objectForKey:@"posts"];
//further code

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM