JSON Array Format

I am working on an iPhone application on which I have POST my data in JSON array format, I tried it and sent it, but did not receive it as a JSON array. I used the following code to create and send my array:

NSMutableArray *playsArr=[[NSMutableArray alloc]init];

int score=[[NSNumber numberWithInt:100 ]intValue];
int game_id=[[NSNumber numberWithInt:1 ]intValue];

NSString *game_version=@"1.1";

// Time stamp in Unix format
int timestamp=[[NSNumber numberWithInt:1312582440]intValue];
int elapsed_time=[[NSNumber numberWithInt:500]intValue];

int level_reached=[[NSNumber numberWithInt:1 ]intValue];

NSString *platform=@"ios";
NSString *hash=@"801356a3b23c8e2ed94455545ddere";

NSString *verificationNew=@"676c66df9b529895a97cd5f4d55ef";

NSLog(@"%@",verification);


NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];

[dict setObject:[NSNumber numberWithInt:score] forKey:@"score"]; 
[dict setObject:[NSNumber numberWithInt:game_id] forKey:@"game_id"];
[dict setObject:game_version forKey:@"game_version"];
[dict setObject:platform forKey:@"platform"];


[dict setObject:[NSNumber numberWithInt:timestamp] forKey:@"timestamp"]; 
[dict setObject:[NSNumber numberWithInt:elapsed_time] forKey:@"elapsed_time"];
[dict setObject:hash forKey:@"hash"];
[dict setObject:[NSNumber numberWithInt:level_reached] forKey:@"level_reached"];
[dict setObject:verification forKey:@"verification"];

NSLog(@"%@",dict);


[playsArr addObject:dict];

[request addPostValue:playsArr forKey:@"plays"];


[request setTimeOutSeconds:600];

[request setDelegate:self];
[request setDidFailSelector:@selector(uploadFailed:)];
[request setDidFinishSelector:@selector(uploadFinished:)];
[request startAsynchronous];

Now the comment I get from the end is this: they do not receive, it is like an array and its return error or null response.

Where am I mistaken in generating a JSON array format? Please help me with the codes ...

Thanks in advance.

I need to make such a structure ......

( [] = >     (         [0] = > [] = 513956         [1] = > [game_id] = 1         [2] = > [game_version] = 1.0         [3] = > [platform] = Web         [4] = > [timestamp] = 1313146039         [5] = > [elapsed_time] = 400         [6] = > [hash] = 61e51000143566bfd2e3aefa7cb7b2ad         [7] = > [level_reached] = 5         [8] = > [] = e56a35341c8dd44fa082ad678cb11593     ) [module] = > [action] = > )

, ...

0
1

JSON. JSON. iOS, ASIHTTPRequest ( , , ), JSON.

, JSON (, TouchJSON) dict JSON. ASIHTTPRequest ( POST):

NSError *error = NULL;
NSData *jsonData = [[CJSONSerializer serializer] serializeObject:dict error:&error];
[request addRequestHeader: @"Content-Type" value: @"application/json"];
[request appendPostData:data];

Update:

, , JSON ( , , , , ):

{
  "plays": [
    {
      "score": 513956,
      "game_id": 1,
      "game_version": "1.0",
      "platform": "Web",
      "timestamp": 1313146039,
      "elapsed_time": 400,
      "hash": "61e51000143566bfd2e3aefa7cb7b2ad",
      "level_reached": 5,
      "verification": "e56a35341c8dd44fa082ad678cb11593"
    }
  ],
  "module": "play",
  "action": "save"
}

:

NSMutableDictionary *dict= [[NSMutableDictionary alloc] init];

NSMutableArray *plays = [[NSMutableArray alloc] initWithCapacity:8];

NSMutableDictionary *play= [[NSMutableDictionary alloc] init];
[play setObject:[NSNumber numberWithInt:score] forKey:@"score"]; 
[play setObject:[NSNumber numberWithInt:game_id] forKey:@"game_id"];
[play setObject:game_version forKey:@"game_version"];
[play setObject:platform forKey:@"platform"];
[play setObject:[NSNumber numberWithInt:timestamp] forKey:@"timestamp"]; 
[play setObject:[NSNumber numberWithInt:elapsed_time] forKey:@"elapsed_time"];
[play setObject:hash forKey:@"hash"];
[play setObject:[NSNumber numberWithInt:level_reached] forKey:@"level_reached"];
[play setObject:verification forKey:@"verification"];
[plays addObject:play];
[play release];

[dict setObject:plays forKey:@"plays"];
[plays release];

[dict setObject:@"play" forKey:@"module"];
[dict setObject:@"save" forKey:@"action"];

NSError *error = NULL;
NSData *jsonData = [[CJSONSerializer serializer] serializeObject:dict error:&error];
[request addRequestHeader: @"Content-Type" value: @"application/json"];
[request appendPostData:data];
+1

All Articles