1.I create class objects and then add value to my class using this code
csJastorPollQuestion *pq = [[csJastorPollQuestion alloc] initWithID:@"01" Name:@"AAA"];
2. I showed "csJastorPollQuestion" in the NSLog that it represents
#<csJastorPollQuestion: id = (null) { ID = 01; Name = AAA; }>
3.I convert "csJastorPollQuestion" to json string with this code
NSData *jsd = [NSJSONSerialization dataWithJSONObject:pq options:NSJSONWritingPrettyPrinted error:&er];
NSString *jsonString = [[NSString alloc] initWithData:jsd encoding:NSUTF8StringEncoding];
4. When I run the project, it showed this error
[NSJSONSerialization dataWithJSONObject:options:error:]: Invalid top-level type in JSON write'
5. What is the correct way to convert "csJastorPollQuestion" to json string?
source
share