How to make a string array (String has json data)
I want to make a line like below
contentlist=["{\"id\":\"id1\"}"]
How can I achieve this?
I tried the method NSString
stringWithFormat:@"contentlist=[\"%@\"]
but it has a character \
when you copy this line and paste it into textedit or sheets or anywhere.
if you give print
this line to be displayed as contentlist=["{"id":"id1"}]
i dont want.
Edited:
Here is my code ..
NSString *stringUrl = <MY SERVER URL STRING>
NSString *param = [NSString stringWithFormat:@"contentlist=[%c%@%c]",34,header,34];
NSData *postData = [param dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
NSError *error;
NSMutableURLRequest *req = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:stringUrl parameters:nil error:&error];
req.timeoutInterval= 40.0;
[req setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[req setValue:postLength forHTTPHeaderField:@"Content-Length"];
[req setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[req setHTTPBody:postData];
And my meaning header
...
{\"id\":\"21ca7309\",\"indexVersion\":0,\"modified\":1501694202014,\"created\":1501691797232,\"modifiedBy\":\"42bebd87be6ddd4a\",\"name\":\"abcd\"}
How does my parameter value look like in mode debug
.
@"contentlist=[\"{\"id\":\"21ca7309\",\"indexVersion\":0,\"modified\":1501694202014,\"created\":1501691797232,\"modifiedBy\":\"42bebd87be6ddd4a\",\"name\":\"abcd\"}\"]
And how I need to go through is like:
contentlist:["{\"id\":\"21ca7309\",\"indexVersion\":0,\"modified\":1501694202014,\"created\":1501691797232,\"modifiedBy\":\"42bebd87be6ddd4a\",\"name\":\"abcd\"}"]
source to share
You don't need to use stringWithFormat
as you mentioned you have NSData
of JSON
if you don't have it then convert it with
NSError *error;
NSData *data = [NSJSONSerialization dataWithJSONObject:yourJSONO options:NSJSONWritingPrettyPrinted error:&error];
Don't forget to check the error before using :)
you can easily get the line from this code below
NSString *str = [[NSstring alloc] initWithData:data encoding:NSUTF8StringEncoding]
source to share