2016-11-29 3 views
0

IはViewController.hこのクラスプロパティのObjective Cでjsonのような構造を作成するには?

ようなビュー・コントローラ・クラスを有してい

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController 

@property (nonatomic, strong) NSDictionary *dictionary; 

@end 

ViewController.m

#import "ViewController.h" 
#import "GoogleMaps.h" 

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    //HOW TO ACCESS THE PROPERTY VALUE HERE 
    self.dictionary = @{}; 


    /DUMP ALL FOUND ITEMS 
    for(DummyContainer* geoItem in geoItems) { 
     NSDictionary *item = @{ 
      @"latitude":geoItem.latitude, 
      @"longtitude":geoItem.longtitude 
     }; 

     self.dictionary[geoItem.geoPoint.name] = item; 
    } 

} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 

予想フォーマットは

var container = { 
    'location':{ 
     'latitude':1233, 
     'longtitude':124 
    } 
} 
でありますクラス内の辞書やアクセスなどのクラスのプロパティを作成する方法

これは、この obj.latitude;

  • のような緯度アクセスQuestion1ため

    let obj = container['location'];

    を経由してアクセスすることができますか?

  • 質問2: JSON構造を作成して値にアクセスする方法は?

私はiOSの新機能です。事前に感謝してください。拡張/変更可能な辞書オブジェクトを作成するための非拡張/不変Dictionaryオブジェクト

@property (strong, nonatomic) NSDictionary *myClassDictionary;  

を作成するための

+0

http://www.appcoda.com/fetch-parse-json-ios-programming-チュートリアル/これは助けることができます – PrafulD

+0

あなたはObjective-CとSwiftを混在させています。私はスイフトとスウィフトで始めることをお勧めします。 – shallowThought

+0

目的のCコードを見つけるのを手伝ってください。私は客観的なCのみを探しています – Sundar

答えて

1

@property (strong, nonatomic) NSMutableDictionary *myClassMutableDictionary; 

挿入この あなたexampleData

'location':{ 
     'latitude':1233, 
     'longtitude':124 
    } 

NSDictionary *dict = @{@"lattitude":@"1233" , @"longitude":@"124"}; 
self.myClassDictionary = @{@"location":dict};//Convert this dictionary into JSON. 

NSError *error; 
NSData *jsonData = [NSJSONSerialization dataWithJSONObject: self.myClassDictionary options:NSJSONWritingPrettyPrinted error:&error]; 
NSString jsonString; 
if (! jsonData) { 
    NSLog(@"Got an error: %@", error); 
} else { 
    jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 
} 
のような辞書内の自分の価値観のすべて
関連する問題