How can i create a json array in below format:
[{"id":"8"},{"id":"9"}]
Using Nsmutable dictionary we can create an above format,but key should be different.
How can i create a json array in below format:
[{"id":"8"},{"id":"9"}]
Using Nsmutable dictionary we can create an above format,but key should be different.
NSDictionary *dict1 = @{
@"id" : @"8"
};
NSDictionary *dict2 = @{
@"id" : @"9"
};
NSArray *array = @[dict1,dict2];
NSData *jsonData=[NSJSONSerialization dataWithJSONObject:array options:NSJSONWritingPrettyPrinted error:nil];
NSString* newStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
Output
[ { "id" : "8" }, { "id" : "9" } ]