标签: jsonmodel

JSONModel与github Mantle框架

我正在构建一个需要大量JSON数据处理的应用程序.在讨论了不同的框架之后,由于其丰富的功能集和易用性,我选择了JSONModel(https://github.com/icanzilb/JSONModel)和github Mantle(https://github.com/github/Mantle). .

它们在功能方面非常相似,如数据转换,归档,复制,自动和自定义键映射等.但是,JSONModel有一些额外的开箱即用映射选项和内置模型级联支持,Mantle是相对更受欢迎,显然github支持它背后.

对我而言,性能和易用性很重要,所以我只是想知道是否有人在使用它们时都有真正的经验并且可以分享,主要是在性能和​​易用性方面.

由于许多内置的键映射选项和模型级联,我自己倾向于JSONModel,但不确定如何使用大型数据集执行.

编辑(2015年4月28日):我最终使用Github Mantle,因为它与我的应用程序架构完美融合,而且它有更多的模块化设计,您可以插入自己的属性格式化程序,核心数据支持,嵌套模型,以及什么不是.

已经使用了近2年,从来没有遇到过它对我不起作用的情况,不开玩笑!它与AFNetworking或Alamofire框架配合使用,适用于Swift.我试图寻找替代方案,当Swift支持仍然很小的补丁,男人,我甚至远远不能找到任何东西.

objective-c ios jsonmodel github-mantle

19
推荐指数
0
解决办法
5181
查看次数

如何使原始类型属性可选?

我想在我的JSONModel类中创建一些原始属性选项.请参阅下面的代码.

#import "JSONModel.h"

@protocol GreenModel <NSObject>
@end

@interface MyModel : JSONModel

@property (nonatomic, assign) NSInteger<Optional> objId;
@property (nonatomic, strong) NSString *name;
@end
Run Code Online (Sandbox Code Playgroud)

有人可以建议一种方法来实现这一目标吗?

jsonmodel

12
推荐指数
1
解决办法
4924
查看次数

NSInvalidArgumentException - [__ NSCFString unsignedLongLongValue]:发送到实例的无法识别的选择器

在使用JSONModel解析我的模型时,我发现了这个例外.

NSInvalidArgumentException -[__NSCFString unsignedLongLongValue]: unrecognized selector sent to instance 0x1782210c0
Run Code Online (Sandbox Code Playgroud)

问题发生在里面,JSONModel.m因为它取决于[NSObject setValue:forKey:].

我找到了一种轻松复制它的方法.

@property NSUInteger uintegerProperty;
[...]
[self setValue:@"1" forKey:@"uintegerProperty"];
Run Code Online (Sandbox Code Playgroud)

这工作在32位,因为setValue最终调用longLongVaue定义NSString,但在64位的情况下,它的调用unsignedLongLongValue是未定义的NSString.

在我的特定情况下,问题是enum在模型中使用.

typedef NS_ENUM(NSUInteger, kNotificationTypeEnum)
{
    kNotificationTypeResponse = 1,
    kNotificationTypeAlert = 2
};
Run Code Online (Sandbox Code Playgroud)

处理这种情况的最佳方法是什么?

堆栈跟踪

2014-12-31 17:48:43.789 mobile-iOS[17851:613] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString unsignedLongLongValue]: unrecognized selector sent to instance 0x10f1feeb0'
*** First throw call stack:
(
    0 …
Run Code Online (Sandbox Code Playgroud)

objective-c 32bit-64bit ios jsonmodel

10
推荐指数
2
解决办法
2882
查看次数

JSONModel中的NSMutableDictionary - EXC_BAD_ACCESS KERN_INVALID_ADDRESS

Crashlytics在我的一个应用程序中报告了这次崩溃,无论我做什么,我都无法重现它.这种情况发生在大约5%的用户身上,所以这是一个非常重要的事情.我发布了崩溃报告的截图以及崩溃报告中提到的方法.不知道怎么解决这个问题?

崩溃报告

这是应用程序崩溃的地方:

#pragma mark - custom transformations
-(BOOL)__customSetValue:(id<NSObject>)value forProperty:(JSONModelClassProperty*)property
{
    if (!property.customSetters)
        property.customSetters = [NSMutableDictionary new];

    NSString *className = NSStringFromClass([JSONValueTransformer classByResolvingClusterClasses:[value class]]);

    if (!property.customSetters[className]) {
        //check for a custom property setter method
        NSString* ucfirstName = [property.name stringByReplacingCharactersInRange:NSMakeRange(0,1)
                                                                       withString:[[property.name substringToIndex:1] uppercaseString]];
        NSString* selectorName = [NSString stringWithFormat:@"set%@With%@:", ucfirstName, className];

        SEL customPropertySetter = NSSelectorFromString(selectorName);

        //check if there's a custom selector like this
        if (![self respondsToSelector: customPropertySetter]) {
            property.customSetters[className] = [NSNull null]; // this is line 855
            return NO;
        }

        //cache the custom setter …
Run Code Online (Sandbox Code Playgroud)

crash xcode exc-bad-access ios jsonmodel

10
推荐指数
1
解决办法
452
查看次数

JSONModel:json到数组?

是否可以使用JSONModel将json解析为JSONModel对象数组?像下面的解析json:

[{"id" : 1}, {"id" : 2}]
Run Code Online (Sandbox Code Playgroud)

两个具有"id"属性的JSONModel对象.

arrays json ios jsonmodel

8
推荐指数
1
解决办法
6661
查看次数

覆盖Swift中的Objective C类方法

我是Swift的初学者,我正在尝试在Swift项目中使用JSONModel.我想从JSONModel覆盖方法keyMapper,但我没有找到如何覆盖模型类中的Objective-C类方法.

该方法的签名是:

+(JSONKeyMapper*)keyMapper;
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

objective-c ios jsonmodel swift

8
推荐指数
1
解决办法
3962
查看次数

带协议的Swift实例变量

我必须将以下几行Objective-c代码翻译成swift.这是来自Objective-c JSONModel-Framework的示例,其中FrameworkOptional提供的协议应用于类型的实例变量NSString.我发现了一个相关的帖子,但我没有设法实现它.随着我的MYModel.swift实现Xcode抱怨Cannot specialize non-generic type NSString

谢谢你的帮助!

MYModel.swift

@objc(MYModel) public class MYModel : JSONModel {
   ...
   public var name : NSString<Optional>
   ...
}
Run Code Online (Sandbox Code Playgroud)

MYModel.h

@interface MYModel : JSONModel
...
@property (strong, nonatomic) NSString<Optional>* name; 
...
Run Code Online (Sandbox Code Playgroud)

JSONModel.h

...
/**
 * Protocol for defining optional properties in a JSON Model class. Use like below to define 
 * model properties that are not required to have values in the JSON input:
 * …
Run Code Online (Sandbox Code Playgroud)

objective-c ios jsonmodel swift

5
推荐指数
1
解决办法
1821
查看次数

Swift问题中的JSONModel

我试图使用JSONModel将json映射到Swift中的模型.

如果模型没有属于JSONModel子类的属性,则一切正常.

所以在示例中这是有效的,并且它成功映射了属性:

class Person: JSONModel {

    var name: NSString?
    var gender: NSString?

}
Run Code Online (Sandbox Code Playgroud)

但是,如果我将JSONModel子类设置为City,则此属性未初始化,并且当我稍后尝试访问city属性时它会崩溃应用程序(我可以成功访问person.name和person.gender,但是在person.city上它崩溃了任何信息):

class Person: JSONModel {

    var name: NSString?
    var gender: NSString?
    var city: City? // City is JSONModel subclass
}
Run Code Online (Sandbox Code Playgroud)

如果它是JSONModel子类,看起来JSONModel不能映射/解析属性.有没有人经历过这个并解决了它?

iphone json ios jsonmodel swift

5
推荐指数
2
解决办法
5986
查看次数

Flutter:pub 已完成,退出代码为 255

我正在通过构建运行器、json 模型和 json 可序列化为我的 flutter 应用程序制作模型。但我收到了这个错误

Unhandled exception:
RangeError (index): Invalid value: Valid value range is empty: 0
#0      _StringBase.[] (dart:core-patch/string_patch.dart:247:55)
#1      changeFirstChar (file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/json_model-0.0.2/bin/json_model.dart:89:41)
#2      getType (file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/json_model-0.0.2/bin/json_model.dart:116:20)
#3      walk.<anonymous closure>.<anonymous closure> (file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/json_model-0.0.2/bin/json_model.dart:62:23)
#4      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8)
#5      walk.<anonymous closure> (file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/json_model-0.0.2/bin/json_model.dart:50:37)
#6      List.forEach (dart:core-patch/growable_array.dart:282:8)
#7      walk (file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/json_model-0.0.2/bin/json_model.dart:38:8)
#8      main (file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/json_model-0.0.2/bin/json_model.dart:18:6)
#9      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
#10     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
pub finished with exit code 255
Run Code Online (Sandbox Code Playgroud)

在我的 pubspec.yaml 文件中,我在开发依赖项中添加了这些 flutter 包:

dev_dependencies:
  flutter_test:
    sdk: flutter
  json_model: ^0.0.2
  json_serializable:
  build_runner:
Run Code Online (Sandbox Code Playgroud)

我想要为其制作模型的 Json 文件:

第一个 json 文件 …

serialization model dart-pub jsonmodel flutter

4
推荐指数
1
解决办法
1万
查看次数

使用JsonModel解析json

在获取json数组时遇到问题.

我正在使用JsonModel库进行json handelling.

我的json数据是:

[
    {
        "TSCard_id": 100,
        "TSCardBackend_id": "TSu1t1",
        "TSCard_date": "10/11/2013",
        "TSCard_resource_id": "",
        "TSCard_resource_name": "",
        "TSCard_job_id": "JOB_M2156 ",
        "TSCard_job_desc": "BAGARIA MILLIPORE - BOM ",
        "TSCard_activity_id": "B03",
        "TSCard_activity_desc": "Closing",
        "TSCard_hours": "4.0",
        "TSCard_chargeableflag": "0",
        "TSCard_desc": "Description:",
        "TSCard_syncflag": "0",
        "TSCard_flag": "",
        "user_id": "1"
    },
    {
        "TSCard_id": 101,
        "TSCardBackend_id": "TSu1t2",
        "TSCard_date": "12/11/2013",
        "TSCard_resource_id": "",
        "TSCard_resource_name": "",
        "TSCard_job_id": "JOB_B0002",
        "TSCard_job_desc": "ABB LIMITED - BLR ",
        "TSCard_activity_id": "NB01",
        "TSCard_activity_desc": "Admin  ",
        "TSCard_hours": "5.0",
        "TSCard_chargeableflag": "1",
        "TSCard_desc": "Description:",
        "TSCard_syncflag": "0",
        "TSCard_flag": "",
        "user_id": "1"
    }
] …
Run Code Online (Sandbox Code Playgroud)

iphone ios jsonmodel

3
推荐指数
1
解决办法
5255
查看次数