I want to post a json object to a request. But JSONWriter doesn’t seem to convert my object, don’t know what I’m doing wrong …
here’s my code for the conversion..
customer = [[Customer alloc] init];
Address *tempAddr = [[Address alloc] init];
tempAddr.Line1=strAddr1 ;
tempAddr.Zip =strPost;
tempAddr.City =strStreet;
[customer setInvoiceAddress:tempAddr];
customer.FirstName=strFirstName;
customer.LastName=strLastName;
customer.CellPhone=strCellPhone;
customer.Phone=strPhone;
customer.Email=strEmail;
SBJsonWriter *writer = [SBJsonWriter alloc];
NSString *jsonConvertedObj = [writer stringWithObject:customer];
NSLog(@"the json converted object ... %@", jsonConvertedObj);
Please help. I’ve no idea what’s wrong with the code above.
AFAIK SBJSONWriter only supports conversion of dictionaries and arrays to JSON strings. It won’t work for arbitrary objects.
Edit: Here is the corresponding implementation, which returns nil if the supplied object is neither a dictionary nor an array.