My Json Response:
{
"xxx": {
"y": {
"id": 1,
"name": "z"
},
"startday": "2016-01-10",
"status": "New",
"total": 1,
"a": [
{
"id": 766,
"b": {
"id": 3,
"name": "c"
},
"d": {
"id": 4
},
"e": {
"id": 1,
"name": "f"
},
"g": {
"id": 8,
"name": "h"
},
"hours": 1,
"comments": "",
"spent_on": "2016-01-10"
}
]
}
}
From this i created a string like this:
NSString * str = @"{\"xxx\":{\"y\":{\"id\":1,\"name\":\"z\"},\"startday\":\"2016-01-10\",\"status\":\"New\",\"total\":1.0,\"a\":[{\"id\":766,\"b\":{\"id\\":3,\\"name\\":\\"c\\"},\\"d\\":{\\"id\\":4},\\"e\\":{\\"id\\":1,\\"name\\":\\"f\\"},\\"g\\":{\\"id\\":8,\\"name\\":\\"h\\"},\\"hours\\":1.0,\\"comments\\":\\"\\",\\"spent_on\\":\\"2016-01-10\\"}]}}";
Then I post this value by below code:
NSData *objectData = [str dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:objectData options:NSJSONReadingMutableContainers error:&jsonError];
if (jsonError == NULL)
{
msgView =@"error msg null";
NSURL *url = [NSURL URLWithString:@"xxx"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSData *requestData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPMethod:@"POST"];
[request setHTTPBody: requestData];
}
It hits server and gets the response.similarly, I get all the values user entering the app.I create the NSstring with concatenation.
NSString* concate = [NSString stringWithFormat:@"%@%@%@%@,%@%@%@,%@,%@%@,%@%,%@,%@,%@%@%@%@%@%@,%@%@,%@%@,%@%@",xx,....];
so i get output response like this after concatenate:
{\"x\":{\"y\":{\"id\":1,
\"name\":\"a\"
},
\"startday\":\"2016-01-10\"
,
\"status\":\"New\"
,{\"total\":1,\"time_entries\":[{\"id\":766,
\"b\":{
\"id\":8,
\"name\":\"c\"
}
,
\"u\":{
\"id\":22
}
,\"d\":{\"id\":1
\"name\":\"e\"
},
\"l\":{
\"id\":8,
\"name\":\"g\"
}
,\"hours\":1,\"comments\":\"\",\"spent_on\":\"2016-01-12\"}]}}
So if pass this, it throws error.here i have to concatenate or combined different strings with other approach.or is there any possibilities to convert string to json response format.or else any other simple way to do this task.please suggest me ideas.