I have a requirement where the objective C code should
consume the WebService
and the response received in JSON format
has to be passed as an argument to a javascript
method for further processing.I am using UIWebView
which will display the appropriate results after processing JSON response.
The issue arises when i try to pass the JSON string to Javascript
method.Javascript method does not simply accept the input.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSString *responseString = [[NSString alloc] initWithBytes:[resultData bytes] length:[resultData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",responseString);
[self returnResponseToJavaScriptMethods:responseString];
}
-(void)returnResponseToJavaScriptMethods:(NSString*)theResponse{
[viewMainWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"retrieveServerResponse('%@')",theResponse]];
}
Is there anything that I am missing out ?? Simple strings are getting passed properly using the same approach.
UPDATE :
Encoding the responseData
to UTF8StringEncoding
did the trick.
[theResponse stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]