0

Now I'm trying to POST jpeg files to MySQL via PHP and GET from MySQL to iOS.

In GET method I encode jpeg(as NSData) and some related data(ex. caption, timestamp) to JSON on PHP script using json_encode().

    {"caption":"(captiondata)","img":"(imagedata)","timestamp":"(timestampdata)"}

Then I set the datas into array like,

    [{"caption":"(captiondata)","img":"(imagedata)","timestamp":"(timestampdata)"},
     {"caption":"(captiondata)","img":"(imagedata)","timestamp":"(timestampdata)"},
     .......,
     {"caption":"(captiondata)","img":"(imagedata)","timestamp":"(timestampdata)"}]

I believe I can parse and get this JSON by echo (json_encode ()) on PHP and SBJsonParser on iOS but nothing returns to my App. Here's my code in iOS.(Also I use TTURLRequest by Three20)

    TTURLRequest* request = [TTURLRequest requestWithURL:url delegate:self];
    request.cachePolicy = cachePolicy;
    TTURLJSONResponse* response = [[[TTURLJSONResponse alloc] init] autorelease];
    request.response = response;
    [request send];

    - (void)requestDidFinishLoad:(TTURLRequest*)request {
        TTURLJSONResponse* response = request.response;
        NSLog(@"%@",response);
    }
nakazy
  • 31
  • 4
  • If you are targeting for iOS5+ then consider using Apple's own JSON parser. http://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html – Devraj Jun 05 '12 at 10:35
  • @Devraj It seems to be so good. Thanks for your answer. – nakazy Jun 05 '12 at 12:47
  • What's the output you're getting in the console? try to put a `NSLog(@"didFinishLoad fired");` to tell if the `requestDidFinishLoad` is getting fired or not. – aporat Jun 06 '12 at 19:11

1 Answers1

0

Can you print all the logs in requestDidFinishLoad:?

The response is the rootObject of TTURLJSONResponse.

- (void)requestDidFinishLoad:(TTURLRequest*)request {

    TTURLJSONResponse *response = request.response;
    NSDictionary *dict = response.rootObject;
    NSLog(@"dict : %@",dict);

}

In your case,

- (void)requestDidFinishLoad:(TTURLRequest*)request {
    TTURLJSONResponse* response = request.response;
    NSLog(@"%@",response);
}

The response may look like <TTURLJSONResponse: 0x125398c0>

If still nothing returns, you may check the requestDidFinishLoad: is been called and not the cache issue.

bradley
  • 648
  • 5
  • 6
  • Thanks for your answer. I changed my code and checked but PHP returns only **()**. I set request.cachePolicy = TTURLRequestCachePolicyNone now. – nakazy Jun 06 '12 at 01:13