1

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": [
   {
       "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"
   }
]
}

Any Suggestions?

3
  • 1
    Isn't it a Dictionary in an Array in a Dictionary? I might be wrong Commented Jan 17, 2012 at 10:30
  • you are right. I solved considering your solution. Commented Jan 17, 2012 at 10:55
  • 1
    @Dilip Don't forget to accept the answer that helped you - that's how StackOverflow grows and can help others. stackoverflow.com/faq Commented Jan 17, 2012 at 11:27

3 Answers 3

3

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 :)

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

first you take your json responce in dictionary and than pass into array

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.