NSDictionary 到 NSArray 再返回 NSDictionary

发布于 2024-12-17 08:18:32 字数 5306 浏览 0 评论 0原文

我试图在我的 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 包含我的数组中的所有键。 非常感谢。

I'm trying to show comments from disqus.com in my UITableView.

Now I have:
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

In my *.h file I have this:

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

And my comments array text:

(
        {
        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;
    }
)

I want to have NSDictionary with all keys, from my array.
Thank you very much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

刘备忘录 2024-12-24 08:18:32

你可以尝试这个:

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

我认为你在“cellForRowAtIndex”方法中使用这个......所以如果是......那么在该方法最后向单元格返回“是”之前释放字典。否则有时它可能会给你错误或错误的数据..快乐编码:)

you can try this one:

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

I think you are using this in your "cellForRowAtIndex" method...So if yes..then before returning YES to the cell at last of this method release the dictionary. Otherwise sometine it may give you error or wrong data..Happy Coding:)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文