Getting JSON reply from webservice
i am try开发者_如何学Cing to get only JSON response from a webservice. i am getting the below response.
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">[["123","testing123"]]</string>
which has XML. how can i get only JSON response. right now i am am getting parsing failed error. how can this be fixed. please help.
Try :
-(NSString *)removeWebserviceJunk:(NSString *)ws {
NSString *withoutXMLPrologue = [ws stringByReplacingOccurrencesOfString:@"\r\n" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [ws length])];
return [withoutXMLPrologue stringByReplacingOccurrencesOfString:@".*<string .*>(.*)<\\/string>" withString:@"$1" options:NSCaseInsensitiveSearch | NSRegularExpressionSearch range:NSMakeRange(0, [withoutXMLPrologue length])];
}
And use SBJson (or other JSON library) to convert the resulting string to JSON.
精彩评论