繁体   English   中英

NSDictionary转换为NSArray,然后返回NSDictionary

[英]NSDictionary to NSArray and back to NSDictionary

我正在尝试在UITableView中显示来自disqus.com的评论。

现在我有:1。

//Creating NSArray with comments only from NSDictionary Dict
    comments = [dict objectForKey:@"response"];
            NSLog(@"MessageArray:%@ count:%i", comments, [comments count]);
            [tableViewNew reloadData];

2。

//I'm trying to get NSDictionary from NSArray, but it isn't work
NSDictionary *currentComment = [comments objectAtIndex:indexPath.row];
//currentComment = nil

在我的* .h文件中,我有这个:

NSArray* comments;
@property (retain, nonatomic) NSArray* comments;

和我的评论数组文本:

(
        {
        author =         {
            about = "";
            avatar =             {
                cache = "http://mediacdn.disqus.com/1321567697/images/noavatar92.png";
                permalink = "http://disqus.com/api/users/avatars/itruf.jpg";
            };
            emailHash = 7741f7b9bbf2a05ff782550412b9a513;
            id = 16898031;
            isAnonymous = 0;
            joinedAt = "2011-09-17T17:17:16";
            name = itruf;
            profileUrl = "http://disqus.com/itruf/";
            url = "";
            username = itruf;
        };
        createdAt = "2011-11-19T06:28:28";
        dislikes = 0;
        forum = smartfiction;
        id = 368112946;
        isApproved = 1;
        isDeleted = 0;
        isEdited = 0;
        isFlagged = 0;
        isHighlighted = 0;
        isJuliaFlagged = 1;
        isSpam = 0;
        likes = 0;
        media =         (
        );
        message = "\U0422\U0435\U0441\U0442. \U041f\U0440\U043e\U0448\U0443 \U043d\U0435 \U0433\U043d\U0435\U0432\U0430\U0442\U044c\U0441\U044f.<br><br><br><br>!!!!!!<br><br>\U0410\U0430 \U0411\U0431 \U0412\U0432 \U0413\U0433 \U0414\U0434 \U0415\U0435 \U0401\U0451 \U0416\U0436 \U0417\U0437 \U0418\U0438 \U0419\U0439 \U041a\U043a \U041b\U043b \U041c\U043c \U041d\U043d \U041e\U043e \U041f\U043f \U0420\U0440 \U0421\U0441 \U0422\U0442 \U0423\U0443 \U0424\U0444 \U0425\U0445 \U0426\U0446 \U0427\U0447 \U0428\U0448 \U0429\U0449 \U042a\U044a \U042b\U044b \U042c\U044c \U042d\U044d \U042e\U044e \U042f\U044f";
        parent = "<null>";
        points = 0;
        "raw_message" = "\U0422\U0435\U0441\U0442. \U041f\U0440\U043e\U0448\U0443 \U043d\U0435 \U0433\U043d\U0435\U0432\U0430\U0442\U044c\U0441\U044f.\n\n\n\n!!!!!!\n\n\U0410\U0430 \U0411\U0431 \U0412\U0432 \U0413\U0433 \U0414\U0434 \U0415\U0435 \U0401\U0451 \U0416\U0436 \U0417\U0437 \U0418\U0438 \U0419\U0439 \U041a\U043a \U041b\U043b \U041c\U043c \U041d\U043d \U041e\U043e \U041f\U043f \U0420\U0440 \U0421\U0441 \U0422\U0442 \U0423\U0443 \U0424\U0444 \U0425\U0445 \U0426\U0446 \U0427\U0447 \U0428\U0448 \U0429\U0449 \U042a\U044a \U042b\U044b \U042c\U044c \U042d\U044d \U042e\U044e \U042f\U044f";
        thread = 475714714;
    },
        {
        author =         {
            avatar =             {
                cache = "http://www.gravatar.com/avatar.php?gravatar_id=2c5d4ef0caae2eb294f9f85cff0fa88b&size=32&default=http://mediacdn.disqus.com/1321567697/images/noavatar32.png";
                permalink = "http://www.gravatar.com/avatar.php?gravatar_id=2c5d4ef0caae2eb294f9f85cff0fa88b&size=32&default=http://mediacdn.disqus.com/1321567697/images/noavatar32.png";
            };
            emailHash = 2c5d4ef0caae2eb294f9f85cff0fa88b;
            isAnonymous = 1;
            name = "\U0421\U0435\U0440\U0433\U0435\U0439";
            profileUrl = "http://disqus.com/guest/2c5d4ef0caae2eb294f9f85cff0fa88b/";
            url = "";
        };
        createdAt = "2011-11-18T07:36:47";
        dislikes = 0;
        forum = smartfiction;
        id = 367328215;
        isApproved = 1;
        isDeleted = 0;
        isEdited = 0;
        isFlagged = 0;
        isHighlighted = 0;
        isJuliaFlagged = 1;
        isSpam = 0;
        likes = 1;
        media =         (
        );
        message = "\U041a\U043b\U0430\U0441\U0441!!! \U0420\U0430\U0431\U043e\U0447\U0438\U0439 \U043a\U043e\U043c\U0430\U043d\U0434\U0443\U0435\U0442 \U043c\U0435\U043d\U0435\U0434\U0436\U0435\U0440\U043e\U043c! \U0414\U0430 \U043a\U0430\U043a \U0433\U0440\U0430\U043c\U043e\U0442\U043d\U043e \U043e\U043d \U044d\U0442\U043e \U0434\U0435\U043b\U0430\U0435\U0442! \U0410 \U043c\U0438\U0441\U0442\U0435\U0440 \U0413\U0440\U0438\U043c\U043c\U0435\U0442, \U043f\U043e\U0445\U043e\U0436\U0435, \U0438 \U0432\U043f\U0440\U0430\U0432\U0434\U0443 \U0431\U043e\U043b\U0432\U0430\U043d.";
        parent = "<null>";
        points = 1;
        "raw_message" = "\U041a\U043b\U0430\U0441\U0441!!! \U0420\U0430\U0431\U043e\U0447\U0438\U0439 \U043a\U043e\U043c\U0430\U043d\U0434\U0443\U0435\U0442 \U043c\U0435\U043d\U0435\U0434\U0436\U0435\U0440\U043e\U043c! \U0414\U0430 \U043a\U0430\U043a \U0433\U0440\U0430\U043c\U043e\U0442\U043d\U043e \U043e\U043d \U044d\U0442\U043e \U0434\U0435\U043b\U0430\U0435\U0442! \U0410 \U043c\U0438\U0441\U0442\U0435\U0440 \U0413\U0440\U0438\U043c\U043c\U0435\U0442, \U043f\U043e\U0445\U043e\U0436\U0435, \U0438 \U0432\U043f\U0440\U0430\U0432\U0434\U0443 \U0431\U043e\U043b\U0432\U0430\U043d.";
        thread = 475714714;
    }
)

我想从阵列中获取所有密钥的NSDictionary。 非常感谢你。

您可以尝试以下一种方法:

    NSDictionary *currentComment = [[NSDictionary alloc] initWithDictionary: [comments objectAtIndex:indexPath.row]];

我认为您正在“ cellForRowAtIndex”方法中使用此方法...因此,如果是,则在此方法的最后将YES返回到单元格之前,请释放字典。 否则,可能会给您错误或错误的数据。.快乐编码:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM