dchohfi / KeyValueObjectMapping

Automatic KeyValue Object Mapping for Objective-C, parse JSON/plist/Dictionary automatically
http://dchohfi.com/
MIT License
600 stars 90 forks source link

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

Open rahulvyas opened 7 years ago

rahulvyas commented 7 years ago

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 ?

alan-soares-dev commented 7 years ago

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