首页 > PHP资讯 > HTML5培训技术 > json数据解析

json数据解析

HTML5培训技术
NSDictionary* myInfo =
    [NSDictionary dictionaryWithContentsOfJSONURLString: @"http://api.kivaws.org/v1/loans/search.json?status=fundraising"];
    NSLog(@"1111111%@",myInfo);
    
    
    NSDictionary* information 
    [NSDictionary dictionaryWithObjectsAndKeys: @"orange",@"apple",@"banana",@"fig",nil];
    NSData* json = [information toJSON];
 
 
@interface NSDictionary(JSONCategories)
+(NSDictionary*)dictionaryWithContentsOfJSONURLString: (NSString*)urlAddress;
-(NSData*)toJSON;
@end
@implementation NSDictionary(JSONCategories)
+(NSDictionary*)dictionaryWithContentsOfJSONURLString: (NSString*)urlAddress
{
    NSData* data = [NSData dataWithContentsOfURL:
                    [NSURL URLWithString: urlAddress] ];
    __autoreleasing NSError* error = nil;
    id result = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
    if (error != nil) return nil;
    return result;
}
-(NSData*)toJSON
{
    NSError* error = nil;
    id result = [NSJSONSerialization dataWithJSONObject:self options:kNilOptions error:&error];
    if (error != nil) return nil;
    return result;
}
@end

HTML5培训技术

本文由欣才IT学院整理发布,未经许可,禁止转载。
支持32不支持0