1

I know there are a few frameworks to parse JSON, but how can I generate a JSON string in Objective-C? Will it be something I would have to write myself, or is there something simple already out there?

1

3 Answers 3

3

I personally like json-framework's use of categories on NSObject over having to go through TouchJSON's CJSONDataSerializer interface.

NSDictionary *dict = [NSDictionary dictionaryWithObject:@"b" forKey:@"a"];
NSString *json = [dict JSONRepresentation];
Sign up to request clarification or add additional context in comments.

Comments

0

TouchJSON includes a mechanism to take a dictionary and produce JSON from it:

http://github.com/schwa/TouchJSON

The example code from that page:

NSDictionary *dictionary = [NSDictionary dictionaryWithObject:@"b" forKey:@"a"];
NSError *error = NULL;
NSData *jsonData = [[CJSONDataSerializer serializer] serializeObject:dictionary error&error];

Comments

0

The interface for this framework seems pretty straight forward to use for generating JSON.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.