user3251949 user3251949 - 2 years ago 108
iOS Question

Parse JSON data to label

reponsedata = [[NSMutableData alloc]init];
NSString *loc = [NSString stringWithFormat:@""];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:loc]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];

if (reponsedata)

NSDictionary *Dictionarydetails = [NSJSONSerialization
NSLog(@"The return data is: %@",Dictionarydetails);

NSMutableDictionary *tempdict = [Dictionarydetails valueForKey:@"AppConfig"];
array=[tempdict valueForKey:@"RestInfo"];

NSLog(@"the result are %@",array);
NSLog(@"the result count is are %d",[array count]);

NSDictionary *classDict = [[NSDictionary alloc]init];

for (int i=0; i<[array count]; i++) {
//arr = [Class_location objectForKey:@"class_image"];
classDict =[array objectAtIndex:i];
// NSLog(@"the dict Values are are: %@",classDict);
NSMutableArray *dict1 =[[NSMutableArray alloc]init];
dict1 =[classDict valueForKey:@"RestInfo"];
NSLog(@"the result :%@",dict1);

lb1.text =[classDict valueForKey:@"restaurant_location"];
lbl2.text = [classDict valueForKey:@"restaurant_name"];
lbl3.text = [classDict valueForKey:@"contact_name"];


the problem was I can't get those value to label
well I got my response from server

Answer Source
//your answer for the script this code check the ans in console, i am waiting for your response

- (void)viewDidLoad
[super viewDidLoad];

NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@""]];

[request setHTTPMethod:@"GET"];

[request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"content-type"];

NSError *err;
NSURLResponse *response;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];

 NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:responseData options: NSJSONReadingMutableContainers error: &err];

NSArray *array=[jsonArray objectForKey:@"RestInfo"];

for (int i=0; i<[array count]; i++) {
    NSLog(@"the restrunt==%@",[[array objectAtIndex:i]objectForKey:@"restaurant_location"]);
    NSLog(@"the resname==%@",[[array objectAtIndex:i]objectForKey:@"restaurant_name"]);
    NSLog(@"the resname==%@",[[array objectAtIndex:i]objectForKey:@"contact_name"]);




override func viewDidLoad() {
 var request: NSMutableURLRequest = NSMutableURLRequest(URL: NSURL(string: "")!)
 request.HTTPMethod = "GET"
request.setValue("application/json;charset=UTF-8", forHTTPHeaderField: "content-type")
NSError * err
NSURLResponse * response
var responseData: NSData = NSURLConnection.sendSynchronousRequest(request, returningResponse: response!, error: err!)
var jsonArray: [NSObject : AnyObject] = NSJSONSerialization.JSONObjectWithData(responseData, options: NSJSONReadingMutableContainers, error: err!)
var array: [AnyObject] = (jsonArray["RestInfo"] as! [AnyObject])
for var i = 0; i < array.count; i++ {
    NSLog("the restrunt==%@", (array[i]["restaurant_location"] as! String))
    NSLog("the resname==%@", (array[i]["restaurant_name"] as! String))
    NSLog("the resname==%@", (array[i]["contact_name"] as! String))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download