2013-06-06 31 views
0

我有一個可能非常基本的問題,但我無法弄清楚。 (幾乎週末; P) 我有這個函數ReadOpenCalls(int關係),它從一個關係獲取打開的調用。.NET數組輸出

List<string> messages = new List<string>(); 

if (inboundSet != null && inboundSet.RecordCount > 0) 
{ 
    inboundSet.MoveFirst(); 

    do 
    { 
     messages.Add(inboundSet.Fields["DESCRIPTION"].Value.ToString()); 
     messages.Add(inboundSet.Fields["PK_R_INBOUNDMESSAGE"].Value.ToString()); 

     inboundSet.MoveNext(); 
    } 
    while (!inboundSet.EOF); 

    return messages; 
} 

它通過WCF調用到PHP頁面中。現在,所有的工作完全正常,我唯一的問題是它的輸出:

stdClass Object ([string] => Array ([0] => Webservice [1] => 1004 [2] => Webservice [3] => 1005 [4] => Webservice [5] => 1006 [6] => Webservice [7] => 1007 [8] => Webservice [9] => 1008 [10] => Webservice [11] => 1009 [12] => Webservice [13] => 1010 [14] => Webservice [15] => 1011))

我真正想要的輸出有「互聯網服務和ID的」,在這種情況下,待在一起,而不是所有在一個大陣。

因此,像

[0] => Webservice, 
     1004 
[1] => Webservice, 
     1005 

請幫我一些例子或者好的方向發展了一槍。我會後你買啤酒;)

+0

這有什麼做用PHP。您的C#代碼會創建一個平面列表,而這正是您可以在PHP中訪問的內容。你在這裏有什麼問題?你問如何改變C#代碼? –

+0

是的,我真的很想知道如何實現我想要的輸出。我對.NET並不是很有經驗,所以任何一個朝着好的方向發展都是不錯的:D – Matheno

回答

3

而不是調用Add方法的兩倍,就像你在這裏做的:

do 
{ 
    messages.Add(inboundSet.Fields["DESCRIPTION"].Value.ToString()); 
    messages.Add(inboundSet.Fields["PK_R_INBOUNDMESSAGE"].Value.ToString()); 
    inboundSet.MoveNext(); 
} 

叫它一次每次迭代,並添加值。

do 
{ 
    string desc = inboundSet.Fields["DESCRIPTION"].Value.ToString(); 
    string inboundMsg = inboundSet.Fields["PK_R_INBOUNDMESSAGE"].Value.ToString() 
    messages.Add(desc +", "+inboundMsg); 
    inboundSet.MoveNext(); 
} 

如果需要斷行,那麼這樣做:

do 
{ 
    string desc = inboundSet.Fields["DESCRIPTION"].Value.ToString(); 
    string inboundMsg = inboundSet.Fields["PK_R_INBOUNDMESSAGE"].Value.ToString() 
    messages.Add(desc +",\n"+inboundMsg); 
    inboundSet.MoveNext(); 
} 
+0

我欠你一杯啤酒!非常感謝,但你能解釋一下你現在做了什麼嗎?你給出了2個值的名稱,然後將它們加在一起?我想我現在明白了。 :D – Matheno

+0

@Marijke歡迎您。我只添加了名稱「desc」和「inboundMsg」,以使代碼「看起來不錯」。您可以輕鬆地在一行中完成:'message.Add(inboundSet.Fields [「DESCRIPTION」]。Value.ToString()+「,」+ inboundSet.Fields [「PK_R_INBOUNDMESSAGE」]。Value.ToString()) ;'沒有變量:) –

+1

就像我想的那樣,哈哈,它看起來更好用的名字哈哈;)你真的救了我的一天和週末! – Matheno