2011-01-12 97 views
0

我想從web服務獲取唯一的JSON響應。我得到下面的迴應。從webservice獲取JSON回覆

<?xml version="1.0" encoding="utf-8"?> 
<string xmlns="http://tempuri.org/">[["123","testing123"]]</string> 

它有XML。我怎樣才能得到唯一的JSON響應。現在我正在解析失敗的錯誤。這怎麼能解決。請幫忙。

+0

<?XML版本= 「1.0」 編碼= 「UTF-8」?> <字符串的xmlns = 「http://tempuri.org/」> [[ 「123」, 「是testing123」]] – Rajashekar 2011-01-12 13:08:49

+0

不確定xml標籤在第一篇文章中是如何被忽略的。 – Rajashekar 2011-01-12 13:09:34

回答

0

嘗試:

-(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])]; 
} 

並使用SBJson(或其他JSON庫)所得到的字符串轉換成JSON。