NSString* items = @"{"items":["item0","item1","item2"]}";
NSData *data= [items dataUsingEncoding:NSUTF8StringEncoding];
NSError *error = nil;
id jsonObject = [NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingAllowFragments
error:&error];
if ([jsonObject isKindOfClass:[NSDictionary class]]){
NSDictionary *dictionary = (NSDictionary *)jsonObject;
NSLog(@"Dersialized JSON Dictionary = %@", dictionary);
}else if ([jsonObject isKindOfClass:[NSArray class]]){
NSArray *nsArray = (NSArray *)jsonObject;
NSLog(@"Dersialized JSON Array = %@", nsArray);
} else {
NSLog(@"An error happened while deserializing the JSON data.");
}
NSDictionary *dict = (NSDictionary *)jsonObject;
NSArray* arr = [dict objectForKey:@"items"];
NSLog(@"list is %@",arr);
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.");
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有