开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜