【发布时间】:2016-11-29 13:13:42
【问题描述】:
我有这样的视图控制器类
ViewController.h
#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
}
}
这可以通过
let obj = container['location'];
像这样的纬度访问
obj.latitude;
- 问题1:如何创建类属性作为字典并在类内部访问?
- 问题2:如何创建JSON结构并访问值?
我是 iOS 新手,请帮助我提前谢谢。
【问题讨论】:
-
你把 Objective-C 和 Swift 混为一谈了。我建议只从 Swift 和 Swift 开始。
-
请帮我找出目标c代码。我只在寻找目标 c
标签: ios objective-c json