How to create JSON Array string given below?

后端 未结 3 1325
[愿得一人]
[愿得一人] 2021-01-16 13:06

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\": [         


        
相关标签:
3条回答
  • 2021-01-16 13:41

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

    0 讨论(0)
  • 2021-01-16 13:43

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

    0 讨论(0)
  • 2021-01-16 13:52

    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]];
    
    0 讨论(0)
提交回复
热议问题