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.
Try this:
responseString = [NSString stringWithFormat:@"[%@]", responseString]
There are other ways of acheiving the same thing, I'm sure others will be able to provide more efficient methods, but if responseString
isn't very large then the above should suffice.
Using a NSMutableString you can do it like this:
NSMutableString *str = [[NSMutableString alloc] initWithString:@"Overflow"];
[str insertString:@"Stack" atIndex:0];
After that the NSMutableString str will hold:
"StackOverflow"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With