2010-09-25 38 views
0

我有一個JSON字符串,我知道問題在哪裏,我只是不知道該怎麼做。我查了JSON字符串中的「禁止的字符」,但它不起作用。 當您爲iPhone的FBStreamDialog運行show-method時,會出現一個視圖,看看它最終在牆上發佈時的樣子。JSON字符串中轉義字符的問題

當我的JSON字符串中的「description」屬性被硬編碼爲@「Testing」時,會發生這種情況。但只要我添加文本從它看起來像這樣一個數據源獲取,這是行不通的:

  "description":" 

    LIVE: Uk's No:1 Reggae Singer Bitty Mclean + Joey Fever, Sthlms No:1 Reggae Voice. 

     DJs 
     Deejay Flash & Micke Goulos + Mc Fabulous G. 

     The Vinyl Bar 
     Up... 

" 

注:我只顯示「說明」的JSON字符串的-property,因爲問題出在哪裏。

所以我試圖做的是,正如我之前解釋的,在「description」屬性中添加字符串「Testing」。這工作。當然,我想擁有「描述」的數據源屬性。於是,我就替換所有字符,是不是與此代碼的一封信:

shortString = [shortString stringByReplacingOccurrencesOfString:@"&" withString:@"och"]; 
shortString = [shortString stringByReplacingOccurrencesOfString:@"+" withString:@"plus"]; 
shortString = [shortString stringByReplacingOccurrencesOfString:@"," withString:@"komma"]; 
shortString = [shortString stringByReplacingOccurrencesOfString:@"'" withString:@"apostrof"]; 
shortString = [shortString stringByReplacingOccurrencesOfString:@":" withString:@"colon"]; 

的輸出是:

"description":"LIVEcolon Ukapostrofs Nocolon1 Reggae Singer Bitty Mclean plus Joey Feverkomma Sthlms Nocolon1 Reggae Voice. 

DJs 
Deejay Flash och Micke Goulos plus Mc Fabulous G. 

The Vinyl Bar 
Up... 

它看起來像一個可批准的JSON字符串?

但顯然不是,因爲如果我使用數據源「description」-property,facebook視圖永遠不會顯示它將如何顯示。它只顯示文本框「你在想什麼」。

這讓我瘋狂。

+0

我很絕望,它顯示。只是試圖替換數字「1」......哦,我的天......;) – 2010-09-25 14:22:40

+0

我可以補充一點,我根本沒有收到錯誤信息。 – 2010-09-25 15:49:19

回答

2

終於!

我明白你爲什麼沒有回答這個問題。你怎麼知道facebook連接不允許\ n在他們的StreamDialog中。無論如何,不​​適用於iPhone。

所以解決的辦法是用替換\ n用空格或任何你想要的。

+0

我以爲我有同樣的轉義問題,但事實證明,我工作後,我也刪除了\ n。感謝您發佈解決方案 – 2010-10-25 14:21:02