douliao5467 2012-06-05 09:52
浏览 44

SBJson从PHP解析JSON

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);
    }
  • 写回答

1条回答 默认 最新

  • dragon4808 2012-06-05 10:32
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据