1

I have a NSMutableArray with objects and i want convert it to JSON to send Web Service a NSString with it information.

I have SBJSON and JSONKit frameworks, but i can't do it. Im doing it with:

 NSString *JSONData=[mutablearray JSONRepresentation];

 NSString *JSONData=[mutablearray JSONString];

How could I achieve this?

1
  • 2
    What is meant "i can't do it"? Commented Apr 19, 2012 at 10:00

2 Answers 2

3

You can use this code:

NSArray *keys = [NSArray arrayWithObjects:@"key",nil];
NSArray *objects = [NSArray arrayWithObjects:object,nil];
NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
NSString* jsonString = [jsonDictionary JSONRepresentation];
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];

You can now send jsonData to the server.. Hope it helps !

Sign up to request clarification or add additional context in comments.

1 Comment

This is giving error for me -JSONRepresentation failed. Error is: JSON serialisation not supported for NSConcreteValue . i am trying to convert my NSMutableArray to JSON .....PLease help
1

If you are willing to try another JSON-Library you should try Touch-Json: https://github.com/TouchCode/TouchJSON

and then serialize your array with the following code:

 NSData *data = [[[CJSONSerializer serializer] serializeArray:array error:nil];

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.