Reputation: 4383
When i request to my web server it send me Json string in request.response.i want to store that json into NSDictionary for parsing and storing it into database. My Json format is
{ "rowNumber" : 3,
[ { "Age" : "2 - 4 years old ",
"AndroidID" : "2",
"Category" : "Chanson",
"Description" : "fourni",
"Size" : 3447196,
"Thumbnail" : null,
"Title" : "test",
"iTunesID" : "2",
"inactive" : false,
"product_id" : 2} ],
[ { "Age" : "2 - 4 years old ",
"AndroidID" : "3",
"Category" : "Chanson",
"Description" : "Animation ",
"Size" : 3447196,
"Thumbnail" : null,
"Title" : "Escargot",
"iTunesID" : "3",
"inactive" : false,
"product_id" : 3
} ]
}
IF i use this code to print String by string to NSlog it display fine but How i can i store that into NDdictionary ??
NSString *response = [[request responseString] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
To store into dictionary i tried this code but this store my json in reverse order
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:request.responseData
options:kNilOptions
error:&error];
for(NSString *key in [json allKeys]) {
NSLog(@"%@",[json objectForKey:key]);
it store it into reverse order. Any help is appreciated.I am using ASIFormDataRequest for networking.
Upvotes: 0
Views: 535
Reputation: 20021
setObject:ForKey:
method and gives the value back when asked with same key used to set the value using objectForKey:
methodUpvotes: 0
Reputation: 3043
Your JSON is not valid.
I check at
Your array format is wrong. Read JSON syntax HERE
This is how it should be done:
{ "rowNumber" : 3,
"Data" : [ {
"Age" : "2 - 4 years old ",
"AndroidID" : "2",
"Category" : "Chanson",
"Description" : "fourni",
"Size" : 3447196,
"Thumbnail" : null,
"Title" : "test",
"iTunesID" : "2",
"inactive" : false,
"product_id" : 2
} ,
{
"Age" : "2 - 4 years old ",
"AndroidID" : "3",
"Category" : "Chanson",
"Description" : "Animation ",
"Size" : 3447196,
"Thumbnail" : null,
"Title" : "Escargot",
"iTunesID" : "3",
"inactive" : false,
"product_id" : 3
} ]
}
Then to store JSON data, I recommend you using my technique HERE. Proper way and quite a beast
Upvotes: 1