2011-06-22 33 views
0

您好,我是新來的iPhone開發如何使用上表視圖文本框顯示解析JSON

我使用的是web服務與那裏我得到JSON響應字符串連接和我解析JSON使用JSONvalue和我responsetring正在使用顯示按鈕,標籤上的解析的JSON ...

當我按一下按鈕解析JSON它會顯示在標籤領域..

我的問題是可以通過v有一個文本框,按鈕和網頁流量或桌面在用戶界面..

當我在文本字段中輸入特定的方法作爲json文件是巨大的,並按下按鈕shd在web視圖或表格視圖上顯示特定方法的內容..

這是可能的嗎?如果是的話如何實現?

感謝ü

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 


    [connection release];  

    NSString *responseString = [[NSString alloc] initWithData:dataWebService encoding:NSUTF8StringEncoding]; 


    self.dataWebService = nil; 

    NSArray* latestLoans = [(NSDictionary*) [responseString JSONValue] objectForKey:@"loans"]; 
    [responseString release];  


    NSDictionary* loan = [latestLoans objectAtIndex:0]; 

    //fetch the data 

    NSNumber* fundedAmount = [loan objectForKey:@"funded_amount"]; 

    NSNumber* loanAmount = [loan objectForKey:@"loan_amount"]; 

    float outstandingAmount = [loanAmount floatValue] - [fundedAmount floatValue]; 

    NSString* name = [loan objectForKey:@"name"]; 

    NSString* country = [(NSDictionary*)[loan objectForKey:@"location"] objectForKey:@"country"]; 

    //set the text to the label 
    label.numberOfLines = 0; 

    label.text = [NSString stringWithFormat:@"Latest loan: %@ \n \n country: %@ \n \n µamount $%.2f", name,country,outstandingAmount]; 
+0

您可以嘗試更改您的問題嗎?我不明白你的意思。 – darksky

+0

@Nayefc其實我目前有一個按鈕和UI中的標籤,當我按下按鈕時,它顯示的結果是LABEL..ie,它從JSON文件中獲取並使用解析json在LABEL上顯示...其實我的需求是我的shd在UI中有一個Textfield,按鈕和一個webview ...當我在TextField中輸入一個字符串時,它從JSon文件中搜索例如上面代碼中的「貸款」。它的內容shd在webview中顯示...你有它? – Abhilash

回答

0

如果你想在一個表中的貸款,你應該UITableView念起來Cell Styles

您需要添加表,則表明部分的數量,行中每個部分,每個單元格(行)的內容以及如果其中一行被觸摸時要執行的操作:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    // Return the number of sections. 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    //after turning latestLoans into a property 
    return self.latestLoans.count; 

} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
    } 
    cell.textLabel.text=[[self.latestLoans objectAtIndex:indexPath.row] objectForKey:@"name"]; 
    cell.detailTextLabel.text=[[self.latestLoans objectAtIndex:indexPath.row] objectForKey:@"loan_amount"]; 
    } 
    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    //do something with the row that was selected, like load a table of detailed information 
} 
+0

webview使你想使用它作爲顯示選項?你可以創建一個採用JSON的方法,循環遍歷所有結果,將其轉換爲HTML並顯示出來......就是你想要的東西? –

+0

伍茲你的儀式你告訴我如何做tabelview多虧了很多..這幫助了我......但我灣編碼我們有一個textfield按鈕和webview在UI中,我們在一個文本字段中輸入一個字符串tat shd與json文件中的字符串匹配,shd在webview上顯示匹配的方法... – Abhilash

相關問題