-1

I have all the json data in NSDATA and now I am not understanding how to parse Json objects and show their value in UILabel My code is

-(void)viewDidLoad{
    [super viewDidLoad];

   self.View3Alpha.alpha = 0.5;

///////////////Getting json from Url ///////////////

    NSURL * url = [NSURL URLWithString:@"http://api.openweathermap.org/data/2.5/weather?q=Islamabad"];
    self.jsonData = [NSData dataWithContentsOfURL:url];
    if (self.jsonData != nil) {

        NSError * error = nil;

        id result = [NSJSONSerialization JSONObjectWithData:self.jsonData options:NSJSONReadingMutableContainers error:&error];
        if (error == nil) {
           NSLog(@"%@",result);

         self.jsonArray = [NSJSONSerialization JSONObjectWithData:self.jsonData options:kNilOptions error:&error];

           //  NSLog(@"%@",jsonArray);

           //   int  secondsLeft = [self.jsonArray objectForKey:@"SecondsToStop"];


        }
    }


    ////////////////////////////// Retriving into readable //////////////////////




}
4
  • 1
    possible duplicate of Xcode how to parse Json Objects Commented Jul 9, 2014 at 19:01
  • Why are you parsing the same JSON data twice? And, once you have parsed the data you no longer have JSON, you have plain old NSDictionary and NSArray objects. How you deal with them depends on what data is stored in them, and we can't help you without at least seeing what the data is. Commented Jul 9, 2014 at 19:26
  • And if you do not have a reasonable understanding of the C language and of basic object-oriented principles you should not be programming in Objective-C. Commented Jul 9, 2014 at 19:28
  • {"coord":{"lon":73.04,"lat":33.72},"sys":{"message":0.1894,"country":"PK","sunrise":1404864299,"sunset":1404915672},"weather":[{"id":800,"main":"Clear","description":"Sky is Clear","icon":"01d"}],"base":"cmc stations","main":{"temp":305.804,"temp_min":305.804,"temp_max":305.804,"pressure":940.82,"sea_level":1012.74,"grnd_level":940.82,"humidity":62},"wind":{"speed":1.41,"deg":109.003},"clouds":{"all":0},"dt":1404888361,"id":1176615,"name":"Islamabad","cod":200} Commented Jul 9, 2014 at 21:08

1 Answer 1

0

In the code you posted above, you should inspect what is in your result variable. result should be of type NSDictionary and you can retrieve its contents via [result valueForKey:@"someDictionaryKey"]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.