标签: nsdictionary

从RSS Feed创建NSDictionary?

我用Google搜索了一下,但在这个问题上找不到很多东西.我有一个RSS提要的URL,我想知道如何以NSDictionary的形式将该内容放入我的应用程序.我可以使用NSData的initWithContentsOfURL吗?

xml iphone objective-c nsdictionary

0
推荐指数
1
解决办法
1046
查看次数

的NSDictionary.如何创建NSDictionary对象

我有这个方法.

[self postRequestWithURL: (NSString *) postArgs:(NSDictionary *) headerArgs: (NSDictionary *) ];
Run Code Online (Sandbox Code Playgroud)

我怎样才能正确调用此方法?

网址是: http://www.google.com/reader/api/0/edit-tag?

帖子args是: "a=user/-/state/com.google/read&ac=edit-tags&s=feed/%@&i=%@&T=%@", entry.link, entry.identifier, tokenString

和标题是:

NSString *authHeader = [NSString stringWithFormat:@"GoogleLogin %@", authString];
[thttpReq addValue:authHeader forHTTPHeaderField:@"Authorization"];

[thttpReq addValue:@"Content-Type" forHTTPHeaderField:@"application/x-www-form-urlencoded"];
Run Code Online (Sandbox Code Playgroud)

sompne可以帮我插入postArgs和HeaderArgs NSDictionary吗?谢谢保罗

iphone objective-c nsdictionary nsmutabledictionary

0
推荐指数
1
解决办法
4702
查看次数

Objective-C - >在NSDictionary中删除最后一个元素

编辑:

代码:

//存储问题字典

- (void)requestFinished:(ASIHTTPRequest *)request
{   
    NSData *responseData = [request responseData];
    NSString *json = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    NSDictionary *qs = [json objectFromJSONString]; 
    self.questions = qs;
    NSLog(@"%@", questions);
    [json release]; 
    [self setQuestions];
    [load fadeOut:load.view withDuration:0.7 andWait:0];
    UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Start" style:UIBarButtonItemStylePlain target:self action:@selector(start:)];          
    self.navigationItem.rightBarButtonItem = anotherButton;
}
Run Code Online (Sandbox Code Playgroud)

我在NSDictionary中有以下项目:

(
   {
        max = 120;
        min = 30;
        question = "Morning Bodyweight (Kg)";
        questionId = 1;
        questionNumber = 1;
        sectionId = 1;
        type = TextInput;
    },
    {
        question = …
Run Code Online (Sandbox Code Playgroud)

iphone xcode objective-c nsdictionary

0
推荐指数
1
解决办法
3649
查看次数

发送到实例的无效选择器 - objectForKey:

运行我的代码时出错.罪魁祸首是我从下面的plist访问一个字符串:

    NSString *sImageFile = [dictionary objectForKey:@"answerCorrect"];
    NSLog(@"%@",sImageFile);
Run Code Online (Sandbox Code Playgroud)

我在这里显示的cocos2d Init中有这个:

-(id) init
{
    // always call "super" init
    // Apple recommends to re-assign "self" with the "super" return value
    if( (self=[super init])) {

        NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
        NSString *ctlLang = [sud valueForKey:@"ctlLang"];
        NSNumber *questionState = [sud valueForKey:@"questionState"];
        NSNumber *scoreState = [sud valueForKey:@"scoreState"];
        gameArray = (NSMutableArray *)[sud valueForKey:@"gameArray"];
        for (NSString *element in gameArray) {
            NSLog(@"\nQL gameArray value=%d\n", [element intValue]);
        }
        NSString *path = [[NSBundle mainBundle] bundlePath];
        NSString *finalPath = [path stringByAppendingPathComponent:ctlLang]; …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nsdictionary nsstring ios

0
推荐指数
1
解决办法
2036
查看次数

为什么我可以从NSDictionary中拉出一个字符串,而不是另一个?

我有一个NSDictionary,我试图从中拉出一个字符串.出于某种原因,最后一个字符串似乎无法恢复(!?!).在下面的代码中,我检索labelString的NSString对象,完全没有问题.但是当我尝试为foo检索NSString时,我总是没有.但我没有看到差异 - 你能看出我做错了吗?

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
                      [NSNumber numberWithInt:CellStyleLabelledStringCell], @"cellStyle",
                      @"name", @"fieldName", 
                      @"Name", @"labelString", 
                      foodItem.name, @"contentString", 
                      @"foo", @"fookey",
                      nil];

NSString *string1 = (NSString *)[dict objectForKey:@"fookey"];
NSString *string2 = (NSString *)[dict objectForKey:@"labelString"];
NSLog(@"[%@][%@]", string1, string2);
Run Code Online (Sandbox Code Playgroud)

日志消息看起来像这样,并备份我在调试器中看到的内容(即string1为null):

2012-03-17 21:35:03.302 QuickList7 [8244:fb03] [(null)] [名称]

真的很困惑.提前致谢.

objective-c nsdictionary

0
推荐指数
1
解决办法
107
查看次数

NSDictionary objectForKey返回错误的值

我正在尝试使用我从服务器获得的JSON响应字典.当我打印字典的描述时,一切都井然有序

    Printing description of dict:
{
    category = 1;
    code = 1;
    name = "xxxx";
    pictureUrl = "xxxx";
    sessionId = xxx;
    status = 0;
}
Run Code Online (Sandbox Code Playgroud)

我需要"代码"值,当我使用objectForKey:@"code"来获取它时,我得到一个错误的值:

int code = [NSDictionary objectForKey:@"code"];
Run Code Online (Sandbox Code Playgroud)

在此之后我打印出代码的值和它的东西,如3483765348,这是非常非常错误的.

为什么会这样?

json key object nsdictionary ios

0
推荐指数
1
解决办法
2986
查看次数

如何检查NSDictionary的哪些键可用?

我要做的是检查我的词典有多深.我的JSON有两种可能性:

stop-schedule:
   0:
      route:
   1:
      route:
Run Code Online (Sandbox Code Playgroud)

要么

stop-schedule:
   route:
Run Code Online (Sandbox Code Playgroud)

所以我正在检查是否需要更深入或更深入.

通常我会做一些类似的事情

[dict objectForKey:@"0"]
Run Code Online (Sandbox Code Playgroud)

检查密钥是否存在(如果没有则返回nill)但是由于某种原因我在iOS上测试时遇到错误.

[__NSCFArray objectForKey:]: unrecognized selector sent to instance
Run Code Online (Sandbox Code Playgroud)

objective-c nsdictionary ios

0
推荐指数
1
解决办法
134
查看次数

如何将字典从NSString初始化为NSArray

我试图创建一个字典(不确定它是否应该NSDictionaryNSMutableDictionary)从NSString一个数组(不确定它是否应该NSArrayNSMutableArray).

属性:

@property(nonatomic, readonly) NSMutableDictionary * categories;
Run Code Online (Sandbox Code Playgroud)

执行:

@synthesize categories = _categories;


- (NSMutableDictionary *)categories{
    if(! _categories) {
        for(PFObject * each in self.products) {
            NSString * currentcategory = [each valueForKey:@"subtitle"];
            NSArray * currentlist = [_categories objectForKey:currentcategory];
            if(! currentlist) {
                currentlist = [[NSArray alloc] init];
            }
            NSMutableArray * newArray = [currentlist mutableCopy];
            [newArray addObject:each];
            NSArray * newlist = [NSArray arrayWithArray:newArray];
            [_categories setObject:newlist forKey:currentcategory];
        }
    }
    NSLog(@"After constructor the value of the …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nsdictionary ios

0
推荐指数
1
解决办法
234
查看次数

无法将NSDictionary值转换为json

我有NSDictionary值,我想将其转换为Json字符串,如:

{
    body = "10-feb";
    comments =     (
    );
    complete = 1;
    "created_at" = "2014-02-09T15:56:01Z";
    "due_at" = "2014-01-10 20:00:00 +0000";
    "due_on" = "2014-10-02";
    id = 439824;
    "notification_sent" = 0;
    "notify_user" = 0;
    "organization_id" = 972;
    participants =     (
    );
    reminders =     (
    );
    starred = 0;
    "updated_at" = "2014-02-09T15:56:01Z";
    "user_id" = 11129;
}
Run Code Online (Sandbox Code Playgroud)

我将它转换为json的方式是:

- (NSString*) jsonStringWithPrettyPrint:(BOOL) prettyPrint str:(NSDictionary *)str {
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:str
                                                       options:(NSJSONWritingOptions)    (prettyPrint ? NSJSONWritingPrettyPrinted : 0)
                                                         error:&error];

    if (! jsonData) …
Run Code Online (Sandbox Code Playgroud)

json objective-c nsdictionary ios nsjsonserialization

0
推荐指数
1
解决办法
395
查看次数

Swift的字典键列表与Objective-C不同

Swift中的列表字典键行为与Objective-C不同.
Objective-C的:

NSDictionary *myDict = @{@"key1": @"One",@"key2": @"Two",@"key3": @"Three"};

for (NSString *myKey in myDict) {
    NSLog(@"key: %@",myKey);
}
Run Code Online (Sandbox Code Playgroud)

Objective-C调试输出:

key: key1 
key: key3
key: key2 
Run Code Online (Sandbox Code Playgroud)

但Swift表现不同:

let stringOfStrings = ["key1":"value1", "key2":"value2"]

for key in stringOfStrings {
    println(key)
}
Run Code Online (Sandbox Code Playgroud)

斯威夫特的输出:

(key2, value2)
(key1, value1)
Run Code Online (Sandbox Code Playgroud)

如何使Swift像Objective-C一样执行; 即,仅列出键?

nsdictionary swift

0
推荐指数
1
解决办法
2047
查看次数