ios - Swift. Mapping from JSON to object model. Array of Array -


There is a model in JSON format

  {"offline": incorrect, "data": {"Path": [[{"Latitude": 56.789351316653, "Longitude": 60.6053340947616}, {"Latitude": 56.78674, "Longitude": 60.60613}], [{"Latitude": 56.79071, "Longitude": 60.60492} , And the object model at the speed  

Issue: {"latitude": 56.79129, "longitude": 60.60493}]]}}

Json's path field can not be parsed, because there is an array of arrays that works well in all cases of arrays with a single dimension.

I had to do something like that. I considered the implementation of mtl_JSONArrayTransformerWithModelClass which changes an array of MTLModels and their structures. So I have created a similar transformer, which expects the array of dictionaries / MTLModels. . I change each array to iterate and dictionaries on the external array with

  + (NSValueTransformer *) JSONArrayOfArraysTransformerWithModelClass: (Class) modelClass NSValueTransformer * arrayTransformer = [NSValueTransformer mtl_JSONArrayTransformerWithModelClass: modelClass]; Return [MTLValueTransformer reversibleTransformerWithForwardBlock: ^ ID (NSArray * arrays) {if (arrays == zero) return zero; NSAssert ([arrays isKindOfClass: NSArray.class], @ "An array is estimated, found:% @", Erase); NSMutableArray * modelArrays = [ability with NSMutableArray array: [arrays count]]; (For Jason Array at ARA) {if (Jasonrey == NSNLL.Annal) {[Model Aid Object: JasonArere]; to continue; } NSAssert ([JSONArray isKindOfClass: NSArray.class], @ "An array of arrays of dictionaries is expected; array of:% @", JSONArray); NSArray * modelArray = [Array transformer has been changed: JSONArray]; If (model array == zero) will continue; [ModelAddOct: ModelArere]; } Return Model Array; } ReverseBlock: ^ id (NSArray * arrays) {if (arrays == zero) return zero; NSAssert ([arrays isKindOfClass: NSArray.class], @ "Expected an array of arrays of MTLModels, found:% @", arrays); NSMutableArray * modelArrays = [Capacity with NSMutableArray array: ModelArerez coat]; (ID ModelArray in ARD) {if (modelArray == NSNull.null) {[modelArrays addObject: NSNull.null]; to continue; } NSASARArt ([ModelArrayHindindOfClass: NSARRA.clus], @ "An array of arrays was estimated, array of:% @", modelArere); NSArray * array = [arrayTransformer reverse transcript value: modelArere]; If (array == zero) will continue; [Model addObject: array]; } Return Model Array; }];   

}

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -