質問

Learning steeply on this one so I'd say it's 99% my mistake somewhere.

Trying a simple procedure for my first app. I want to get data from the web service and output something to a label. I'm a .NET developer so web service has been done and returns JSON data as expected in a browser. {"GetVenuesForBrandResult":[{"brandID":0,"createdDate":"/Date(-62135596800000+0000)/","venueID":2,"venueName":"HMV Records"}]}

After looking at SO, decided to use AFNetworking, version 2.0, loaded as a pod.

So everything works in terms of getting the data but 2 questions please; 1) the output view in Xcode shows data thus; GetVenuesForBrandResult=({brandID = 0;createdDate = "/Date(-62135596800000+0000)/";venueID = 2;venueName = "HMV Records"; } ); Is this just XCode5 formatting for display purposes? And will my data be json in real terms? 2) How do I consume this? Tried checking for isKindOfClass to be an nsarray or nsdictionary and these if conditions are never met. Which led me to suspect Q1 is the issue.

Your help to an Xcode newbie is appreciated.


as per Paul's excellent hint, the relevant part of my code is here; the web service link is hard coded for now for test purposes

NSString *urlstring =     @"http://hiddenurl/shopBeaconService/Service1.svc/GetVenuesForBra nd/1";
        //NSString *str2 = self.email.text;
        //NSString *str3 = @"/";
        //NSString *str4 = [self.password text];
        //NSString *urlstring = [NSString stringWithFormat:@"%@%@%@%@",str1,str2,str3,str4];

        NSURL *url = [NSURL URLWithString:urlstring];

        NSURLRequest *request = [NSURLRequest requestWithURL:url];

        AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
        operation.responseSerializer = [AFJSONResponseSerializer serializer];
        [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation,id responseObject)
         {
             NSLog(@"%@",responseObject);

            // NSDictionary *item = [responseObject objectForKey:@""];
            // NSString *title = [item objectForKey:@"venueName"];

             //NSLog(@"venue= %@",title);
         } failure:nil];

        [operation start];
役に立ちましたか?

解決

The response object when you use the AFJSONResponseSerializer is an NSDictionary. What you are seeing in your log is the output from [responseObject description] - a method that prints a description for logging purposes.

Ray Wenderlich has a good tutorial on AFNetworking

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top