如何使用上表视图文本框显示解析JSON

问题描述:

您好,我是新来的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

如果你想在一个表中的贷款,你应该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