简体   繁体   中英

NSDictionary to NSArray and back to 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.

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:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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