私は2次元配列を返す.asmx Webサービスを使用していますrow1={'id1','name1'}, row2={'id2','name2'}
が、私はそうすることができません。
コードセクション
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public Array getAlbumsAndPhotos()
{
DataTable resultText = new DataTable();
resultText = AdminUserDataAccess.getAlbumsAndPhotosforAsmx();
string[,] ResultResponse = new string[resultText.Rows.Count , resultText.Columns.Count];
for (int i = 0; i < resultText.Rows.Count; i++)
{
for (int j = 0; j < resultText.Columns.Count; j++)
{
ResultResponse[i, j] = resultText.Rows[i][j].ToString();
}
}
return ResultResponse;
}
これにより、次のような出力が得られます。
[0,0]:"id1"
[0,1]:"name1"
[1,0]:"id2"
[1,1]:"name2"
単一の 0 番目のインデックス (id1 と name1 を使用) と 1 番目のインデックス (id2 と name2 を使用) を使用して、4 行ではなく 2 行を返す必要があります。ある種のネストされた配列出力が予期されます。しかし、私はそうすることができません。どんな助けでも大歓迎です。:)
編集:解決策
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<string[]> getAlbumsAndPhotos()
{
DataTable resultText = new DataTable();
resultText = AdminUserDataAccess.getAlbumsAndPhotosforAsmx();
string[] rowsValues = new string[resultText.Rows.Count];
var list = new List<string[]>();
for (int i = 0; i < resultText.Rows.Count; i++)
{
string col1 = resultText.Rows[i][0].ToString();
string col2 = resultText.Rows[i][1].ToString();
list.Add(new[] { col1, col2});
}
return list;
リストまたは配列リストを使用してこれを実装できます。ありがとう。:)