开发者

PHP to JSON to iPhone [duplicate]

开发者 https://www.devze.com 2023-03-20 18:47 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Cannot Get开发者_StackOverflow ASIHTTPRequest callback delegate to trigger
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Cannot Get开发者_StackOverflow ASIHTTPRequest callback delegate to trigger

I have a php file which outputs the following JSON:

[{"0":"5","questionId":"5","1":"Morning Heart Rate","question":"Morning Heart Rate","2":"5","questionNumber":"5","3":"1","sectionId":"1"},{"0":"4","questionId":"4","1":"Evening Urine Colour","question":"Evening Urine Colour","2":"4","questionNumber":"4","3":"1","sectionId":"1"},{"0":"3","questionId":"3","1":"Evening Bodyweight","question":"Evening Bodyweight","2":"3","questionNumber":"3","3":"1","sectionId":"1"},{"0":"2","questionId":"2","1":"Morning Urine Colour","question":"Morning Urine Colour","2":"2","questionNumber":"2","3":"1","sectionId":"1"},{"0":"1","questionId":"1","1":"Morning Bodyweight","question":"Morning Bodyweight","2":"1","questionNumber":"1","3":"1","sectionId":"1"},{"0":"6","questionId":"6","1":"Time of Month (TOM)","question":"Time of Month (TOM)","2":"6","questionNumber":"6","3":"1","sectionId":"1"}]

This can be seen at the following link:

http://dev.speechlink.co.uk/David/get_questionstest.php

I am using JSONKit as the framework for decoding JSON in Objective C. The following method is used to communicate with the php:

//method to

+(void)getQuestions:(NSString*)sectionId{
    NSString* url = @"http://dev.speechlink.co.uk/David/get_questions.php";
    NSURL *link = [NSURL URLWithString:url];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:link]; 
    [request setPostValue:sectionId forKey:@"section"]; 
    [request setDelegate:self];
    [request setDidFinishSelector:@selector(requestFinished:)];
    [request startAsynchronous];    
}

- (void)requestFinished:(ASIHTTPRequest *)request
{
    //NSString *response = [request responseString];
    NSLog(@"hello"); //never prints
}

The delegate is never called...Can anyone explain?


- (void)getQuestions:(NSString*)sectionId 

Declare the method to be an instance method not an class method.

When you set [request setDelegate:self]; self must be an allocated object.


I check the link http://dev.speechlink.co.uk/David/get_questionstest.php and it is giving the response as you described. But in your code the link you used is different from the one you provided above.

http://dev.speechlink.co.uk/David/get_questions.php which is not giving any response and that may be the case why your delegate is not calling. Please change "get_questions.php" with "get_questionstest.php" and it will work fine.

Let me know if any problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号