BerXiu / XJsonObject

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

XJsonObject


Object serialization and network data parsing, automatic mapping array cost object

Language

##Cocoapods

pod 'XJsonObject'

[!] Unable to find a pod with name, author, summary, or descriptionmatching XJsonObject

rm ~/Library/Caches/CocoaPods/search_index.json
pod search XJsonObject

##introduction Will the Json data network request, NSDictionary, array, mapping model for the data.

To save data model object serialization into a dictionary.

##peculiarity Achieve positive reverse mapping object, attribute type automatic judgment, use a dictionary of the corresponding key matching initialized attribute name assignment.

Support types NSString, NSDate, NSNumber, NSArray, constant, SSObject And its subclasses.

For NSDate, if the number is automatically carried out in accordance with the timestamp conversion, if it is a string, according to the provided time format conversion.

Support array object serialization into directly!

##Use

mapping model for the data

    // data
    NSDictionary * dic = @{ @"testObj": @{  @"name": @"test2",
                                            @"intValue": @(80) },
                            @"name":        @"test1",
                            @"intValue":    @"10",
                            @"value":       @{  @"key1": @"value1" },
                            @"testItems":   @[  @{ @"name": @"testName1"},
                                                @{ @"name": @"testName2"},
                                                @{ @"name": @"testName3"}]};
    // add
    Info * obj = [Info objectWithDictionary:dic];

    // output
    NSLog(@"%@", obj.intValue);
    NSLog(@"%@", obj.name);
    NSLog(@"%@", obj.testItems.firstObject.name);
    NSLog(@"%@", obj.testObj.name);
    NSLog(@"%@", obj.testObj.intValue);
    NSLog(@"%@", obj.value.key1);

###Support array object serialization into directly!

    NSArray * arr = @[  @{@"name": @"testName1"},
                        @{@"name": @"testName2"},
                        @{@"name": @"testName3"}];
    
    NSArray * objItems = [InfoItems arrayWithDictionarys:arr];

    for (InfoItems *item in objItems) {
        NSLog(@"%@",item.name);
    }
    
    NSLog(@"%@",obj.dictionaryFormInfoNone);

About


Languages

Language:Objective-C 96.4%Language:Ruby 3.6%