Display all JSON data from NSDictionary to UITableview
By : Nilay
Date : March 29 2020, 07:55 AM
this one helps. I am fairly new to iOS development, been at it for 2 years or so. I have developed an app for my Litecoin mining pool that is able to pull data from the API url in JSON format. I am able to get individual variables from JSON, but I want to display all of the data from the "workers" block into a UITableView. Here is an example of the JSON: , Following code will print worker's information: code :
[json[@"workers"] enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSDictionary *obj, BOOL *stop) {
NSLog(@"worker = %@ : hashrate = %f last_share_timestamp = %f",
key, [obj[@"hashrate"] floatValue], [obj[@"last_share_timestamp"] floatValue] );
}];
|
Get all inside NSDictionary into a UITextView
By : Murthy
Date : March 29 2020, 07:55 AM
hop of those help? I got a NSDictionary and I want to print it into a UITextView. , you should append it to the existing text code :
textview.text = @"";
for(int i=0; i<[array count];i++)
{
dictionary= [array objectAtIndex:i];
//that shows only one line from the dictionary in the textview
textview.text = [textview.text stringByAppendingFormat:@"%@\n",[diction objectForKey:@"text"]]];
//that shows all the dictionary with key "text" in the log
NSLog(@"%@",[diction objectForKey:@"text"]);
}
|
Best way to display JSON (well formatted) in UITextView or UIWebView in iOS
By : alien35man
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , to get formatted JSON string. The solution is to create JSON Object from JSON string, code :
let jsonString = "[{\"person\": {\"name\":\"Dani\",\"age\":\"24\"}},{\"person\": {\"name\":\"ray\",\"age\":\"70\"}}]"
var error: NSError?
//1. convert string to NSData
let jsonData = jsonString.dataUsingEncoding(NSUTF8StringEncoding)!
//2. convert JSON data to JSON object
let jsonObject:AnyObject = NSJSONSerialization.JSONObjectWithData(jsonData, options: nil, error: &error)!
//3. convert back to JSON data by setting .PrettyPrinted option
let prettyJsonData = NSJSONSerialization.dataWithJSONObject(jsonObject, options: .PrettyPrinted, error: &error)!
//4. convert NSData back to NSString (use NSString init for convenience), later you can convert to String.
let prettyPrintedJson = NSString(data: prettyJsonData, encoding: NSUTF8StringEncoding)!
//print the result
println("\(prettyPrintedJson)")
|
Copying NSDictionary value in UITextview
By : kanica thaploo
Date : March 29 2020, 07:55 AM
I wish this help you I have the following code, where the global variable var fullDict = "" stores dictionary of values. , Based on your comments, you have put the line: code :
userResult_txtView.text = self.fullDict
class ViewController: UIViewController {
...
func showFullDict() {
userResult_txtView.text = self.fullDict
}
}
|
Xcode iOS: Retrieving values from NSDictionary and displaying it in UITextView
By : fitsyu
Date : March 29 2020, 07:55 AM
will help you For dictionary access, you should ideally be using objectForKey:, not valueForKey: (which has to do with key-value coding). I don't know what your original JSON looks like, but if it is like:
|