【问题标题】:Sending a class through json post [duplicate]通过json post发送一个类[重复]
【发布时间】:2013-08-21 20:52:05
【问题描述】:

如何通过json post发送一个NSObject类?

例子:

@interface TestClass : NSObject
 @property (nonatomic,strong) NSString *Value1;
 @property (nonatomic,strong) NSString *Value2;
 @property (nonatomic,strong) NSString *Value1;
@end

在另一个实现TestClass的文件中:

TestClass *test = [[TestClass alloc]init];
test.Value1 = @"First";
test.Value2 = @"Second";
test.Value3 = @"Third";

.....

如何发送测试对象?

【问题讨论】:

  • 仅作记录 - 它不是您要序列化的类,而是该类的 instance。幸运的是,这要简单得多。此外,正常命名约定的属性(和方法)名称以小写开头。
  • stackoverflow.com/a/20996601/730807 中查看我的答案我正在使用这种方式,效果很好,也能满足您的需求。希望这会有所帮助。

标签: ios objective-c json http-post


【解决方案1】:

正如@Carl 指出的那样,您必须convert it first to a JSON object,然后将其作为POST 请求的参数发送。请注意,后端定义了您的数据应如何发送请求。但这是最常见的做法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-10
    • 2012-02-17
    相关资源
    最近更新 更多