1. 我使用以下代码创建类对象并给我的类添加值:
csJastorPollQuestion *pq = [[csJastorPollQuestion alloc] initWithID:@"01" Name:@"AAA"];
2. 我在 NSLog 中显示了 "csJastorPollQuestion",表示它已存在。
#<csJastorPollQuestion: id = (null) { ID = 01; Name = AAA; }>
3. 我用以下代码将 "csJastorPollQuestion" 转换为 JSON 字符串:
NSData *jsd = [NSJSONSerialization dataWithJSONObject:pq options:NSJSONWritingPrettyPrinted error:&er];
NSString *jsonString = [[NSString alloc] initWithData:jsd encoding:NSUTF8StringEncoding];
4. 当我运行我的项目时,出现了以下错误信息:
this
[NSJSONSerialization dataWithJSONObject:options:error:]: Invalid top-level type in JSON write'
5.如何正确将“csJastorPollQuestion”转换为JSON字符串?