新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > iOS開發常用的第三方類庫

        iOS開發常用的第三方類庫

        作者: 時間:2016-10-08 來源:網絡 收藏
        // We don't want *all* the individual messages from the
        // SBJsonStreamParser, just the top-level objects. The stream
        // parser adapter exists for this purpose.
        adapter = [[SBJsonStreamParserAdapter alloc] init];
        // Set ourselves as the delegate, so we receive the messages
        // from the adapter.
        adapter.delegate = self;
        // Create a new stream parser..
        parser = [[SBJsonStreamParser alloc] init];
        // .. and set our adapter as its delegate.
        parser.delegate = adapter;
        // Normally it's an error if JSON is followed by anything but
        // whitespace. Setting this means that the parser will be
        // expecting the stream to contain multiple whitespace-separated
        // JSON documents.
        parser.supportMultipleDocuments = YES;
        }
        #pragma mark SBJsonStreamParserAdapterDelegate methods
        - (void)parser:(SBJsonStreamParser *)parser foundArray:(NSArray *)array {
        [NSExceptionraise:@unexpected format:@Should not get here];
        }
        - (void)parser:(SBJsonStreamParser *)parser foundObject:(NSDictionary *)dict {
        NSLog(@SBJson parser foundObject);
        // 處理返回的數據
        }
        // 使用ASIHTTPRequest請求測試
        - (void) loadData {
        __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
        [request setRequestMethod:@POST];
        [request setCompletionBlock:^{
        // Use when fetching text data
        //NSString *responseString = [request responseString];
        // Use when fetching binary data
        NSData *responseData = [request responseData];
        NSLog(@Connection didReceiveData of length: %u, responseData.length);
        // Parse the new chunk of data. The parser will append it to
        // its internal buffer, then parse from where it left off in
        // the last chunk.
        SBJsonStreamParserStatus status = [parser parse:responseData];
        if (status == SBJsonStreamParserError) {
        NSLog(@Parser error: %@, parser.error);


        關鍵詞:

        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 开封县| 河津市| 原阳县| 绥滨县| 五大连池市| 犍为县| 当涂县| 密云县| 百色市| 迁安市| 遂川县| 田林县| 富民县| 两当县| 额济纳旗| SHOW| 正镶白旗| 永嘉县| 广东省| 河池市| 绩溪县| 绥滨县| 柘荣县| 益阳市| 丽水市| 南通市| 吴桥县| 宜兰县| 阳西县| 沐川县| 尚义县| 德格县| 平舆县| 巍山| 罗田县| 嘉义市| 沛县| 鹰潭市| 太康县| 嘉祥县| 宝兴县|