views:

11

answers:

1

I am getting a JSON response from a web service but it is not wrapped by the [] tags required by the JSON parser I am using so I need to Append and Prepend those characters to my NSString before I pass that to the JSON parser.

Here is what I haver so far:

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
responseString = [responseString stringByAppendingFormat:@"]"];

The appending works perfectly now I just need to prepend the [ to this, can't seem to find this method.

A: 

Try this:

responseString = [NSString stringWithFormat:@"[%@]", responseString]

There are other ways of acheiving the same thing, I'm sure others will be provide more efficient methods, but if responseString isn't very large then the above should suffice.

dreamlax
DOH! I can't believe I didn't think of that - thanks!
Slee