KeyValueObjectMapping icon indicating copy to clipboard operation
KeyValueObjectMapping copied to clipboard

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

Open rahulvyas opened this issue 7 years ago • 1 comments

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 ?

rahulvyas avatar Mar 10 '17 12:03 rahulvyas

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]; }

alan-soares-dev avatar Jul 24 '17 23:07 alan-soares-dev