Skip to content

how to parse a json with array at root and no root key defined #87

Open

Description

@rahulvyas

I am receiving this kind of response from my server

[
{
"created_at" : "Sat Apr 14 00:20:07 +0000 2012",
"id_str" : 190957570511478784,
"text" : "Tweet text"
},
{
"created_at" : "Sat Apr 14 00:20:07 +0000 2012",
"id_str" : 190957570511478784,
"text" : "Tweet text"
}
]

How do I parse this ?

Activity

  1. changed the title [-]how to parse a json with no root key[/-] [+]how to parse a json with array at root and no root key defined[/+] on Mar 10, 2017
  2. alan-soares-dev commented on Jul 24, 2017

    @alan-soares-dev

    Convert the response to NSArray, then iterate:

    NSArray *responseArray = responseObject;
    DCKeyValueObjectMapping *parser = [DCKeyValueObjectMapping mapperForClass:[Tweet class]];

    for (int i = 0; i < [responseArray count]; i++) {
    Tweet *tweet = (Tweet *) [parser parseDictionary:responseArray[i]];
    [self.tweets addObject:tweet];
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions