ios - RestKit 映射字符串数组以发布到服务器

标签 ios json restkit

我在向服务器发送字符串数组时遇到问题:

我的映射是这样的:

+(RKMapping*)occurrenceCreateMapping {

    RKObjectMapping *occurrenceCreateMapping = [RKObjectMapping requestMapping];

    [occurrenceCreateMapping addAttributeMappingsFromDictionary:@{
     @"observedOn" :@"ObservedOn",
     @"latitude" :@"Latitude",
     @"longitude" :@"Longitude",
     @"address" :@"Address",
     @"host" :@"Host",
     @"pests" : @"Pests",
     @"networkId" :@"NetworkId",
     @"consignmentNumber" :@"ConsignmentNumber"
     }];

    return occurrenceCreateMapping;
}

但实际发布的是这样的:

Post from Charles proxy

这是无效的,因为我的服务器端模型联编程序需要一个字符串数组。

这是我的 OccurrenceCreate 类的代码:

@interface BBOccurrenceCreate : NSObject

@property (nonatomic, retain) NSDate *observedOn;

@property CGPoint location;

@property (nonatomic, retain) NSString  *latitude,
                                        *longitude,
                                        *address,
                                        *host,
                                        *consignmentNumber,
                                        *networkId;

@property (nonatomic,retain) NSArray *pests;

@end

谁能帮我把这个字符串数组映射到 json 数组?我认为这应该很简单?!?!

最佳答案

您可能缺少序列化类型设置,因此 RestKit 默认为 form-url-encoded。显式设置序列化类型以指示 RestKit 生成 JSON。

关于ios - RestKit 映射字符串数组以发布到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18997147/

相关文章:

database - 维护和更新IOS客户端与服务器之间的脱机更改的最佳方法是什么?

iOS7 也从 ViewDidLoad 调用 IBAction 方法

iphone - 在 UITableViewCell 中添加分隔符

objective-c - 需要一个类似于日志 View 的 View

MySQL - 搜索 JSON 数据列

javascript - 如何将 JSON 数据传递到 Nunjucks 文件中?

mysql - 使用 Node.JS 将 JSON 对象数据插入 MySQL

ios - RestKit 完成 block 是否在主 UI 线程上运行?

ios - iOS 10 中 CTCallStateIncoming 的模拟是什么?

ios - RestKit 和 Cocoapods : Mapping operation failed/did not find any mappable values