I want to create and to send JSON Array string given below: I am using JSON Framework, it can parse JSON array but how to create JSON Array
{
\"deferred\": [
Leaving an answer to summarize it all.
As I mentioned in a comment, it is a dictionary in an array in a dictionary.
Dictionaries:
{
"API": "Test1",
"data": "{\"uid\":\"16\",\"cid\":\"22\",\"watch\":\"12\"}",
"timestamp": "12-01-2012 16:05:45"
},
{
"API": "Test2",
"data": "{\"uid\":\"16\",\"cid\":\"22\"}",
"timestamp": "12-01-2012 16:05:45"
},
{
"API": "Test3",
"data": "{\"uid\":\"16\",\"cid\":\"22\",\"type\":\"n\"}",
"timestamp": "12-01-2012 16:05:45"
}
Can be created like that:
NSDictionary *dict3 = [NSDictionary dictionaryWithObjectsAndKeys:@"Test3", @"API"
@"{\"uid\":\"16\",\"cid\":\"22\",\"type\":\"n\"}", @"data"
@"12-01-2012 16:05:45", @"timestamp"
, nil];
These dictionaries are stored in an array.
NSArray *theArray = [NSArray arrayWithObjects: dict1, dict2, dict3, nil];
or you can make a NSMutableArray and add dictionaries there right after creating them.
And that array is in a dictionary:
NSDictionary *theBigDictionary = [NSDictionary dictionaryWithObject:theArray forKey:@"deferred"];
Hope it helps :)
first you take your json responce in dictionary and than pass into array
SBJSON is useful for the same. For better guidance Tutorial: JSON Over HTTP On The iPhone
SBJSON will work like...
SBJSON *json = [[SBJSON new] autorelease];
NSMutableArray *ArrayResponse = [[NSMutableArray alloc] initWithArray:[json objectWithString:responseString error:nil]];