NSArray *myProduct
=
response.products;
NSDictionary *myDict;
NSMutableDictionary *dict
=
[NSMutableDictionary
dictionaryWithCapacity:
4];
for(int
i =
0;i<myProduct.count;++i)
{
//NSLog(@"----------------------");
//NSLog(@"Product
title: %@" ,[myProduct[i] localizedTitle]);
//NSLog(@"Product
description: %@" ,[myProduct[i] localizedDescription]);
//NSLog(@"Product
price: %@" ,[myProduct[i] price]);
//NSLog(@"Product
id: %@" ,[myProduct[i] productIdentifier]);
myDict
=
[NSDictionary
dictionaryWithObjectsAndKeys:
[myProduct[i]
localizedTitle],
@"title",
[myProduct[i]
localizedDescription],
@"desc",
[myProduct[i]
price],
@"price",
[myProduct[i]
productIdentifier],
@"product",
nil];
[dict
setValue:
myDict
forKey:
[myProduct[i]
productIdentifier]];
}
if([NSJSONSerialization
isValidJSONObject:dict])
{
NSError*
error;
NSData
*str
=
[NSJSONSerialization
dataWithJSONObject:dict
options:kNilOptions
error:&error];
NSLog(@"Result:
%@",[[NSString
alloc]initWithData:str
encoding:NSUTF8StringEncoding]);
}
else
{
NSLog(@"An
error happened while serializing the JSON data.");
}