2011-12-02 29 views
0

請考慮下面的代碼:如何在客觀C顯示在UITextView的JSON結果數據

NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:[ NSURL URLWithString:url ]]; // Pulls the URL 
    NSLog(@"jsonreturn#########=%@",jsonreturn); // Look at the console and you can see what the restults are 
    NSData *jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding]; 
    CJSONDeserializer *theDeserializer = [CJSONDeserializer deserializer]; 
    theDeserializer.nullObject = NULL; 
    NSError *error = nil;   

    NSDictionary *dictt = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error]; 
    NSLog(@"###dict=%@", dictt); 
    if (dictt) { 
     rowsForQuestion = [[dictt objectForKey:@"faqdetails"] retain];// NSArray rowsForQuestion 
    } 
    [jsonreturn release]; 

//我有這個數據是在控制檯現在我想打印的UITextView,但我怎麼能做到這一點

faqdetails =  (
       { 
      faqAns = "Yes, Jack Kalis is the best crickter"; 
      faqQues = "who is the best cricketer in present year?"; 
     } 
    ); 
} 

回答

1

您的問題不是特別清楚您想要顯示哪裏,但是將文本拖放到UITextView中並不容易。

[yourTextView setText: [[rowsForQuestion objectAtIndex: 0] objectForKey: @"faqQues"]]; 

以上代碼從抓住rowsForQuestion第一字典,並提出它的值對於@"faqQues"成一個UITextView。

0

假設你有一個名爲myTextView,一個UITextView實例作出任何編程或通過IB,試試這個:

[myTextView setText:faqdetails];