0

我尝试以多种方式对列表进行排序,但没有一个对我有用。我一定做错了什么。我想对列表进行排序,details然后对其进行序列化并将其发送到 UI,以便我在 UI 中有一个排序的列表。所以基本上我想Return strJson返回排序(按排序属性排序)列表。希望我说得通。

<WebMethod(Description:="Get Home Page Items Page Wise", EnableSession:=True)> _
    <ScriptMethod(ResponseFormat:=ResponseFormat.Json)>
    Public Function GetHomePageItemsPageWise(ByVal pageIndex As String) As Object
        Dim details As New List(Of HomePageObject)()

        Dim idObject As New List(Of GetIdBasedOnInterest)()
        idObject = CType(BLL.GetDataByInterests(CType(BLL.GetAccIdFromSocialAuthSession(), Integer)), List(Of GetIdBasedOnInterest))


        Dim cmd As DbCommand = _db.GetStoredProcCommand("GetHomePageObjectPageWise")
        _db.AddInParameter(cmd, "PageIndex", SqlDbType.VarChar, pageIndex)
        _db.AddInParameter(cmd, "PageSize", SqlDbType.Int, 10)
        _db.AddOutParameter(cmd, "PageCount", SqlDbType.Int, 1)
        _db.AddInParameter(cmd, "whereStoryID", SqlDbType.VarChar, idObject(0).StoryIds)
        _db.AddInParameter(cmd, "whereAlbumID", SqlDbType.VarChar, idObject(0).AlbumIds)
        _db.AddInParameter(cmd, "wherePictureID", SqlDbType.VarChar, idObject(0).PictureIds)

        Try
            Using ds As DataSet = _db.ExecuteDataSet(cmd)
                For Each rs As DataRow In ds.Tables(0).Rows
                    Dim homePageObject As New HomePageObject()

                    homePageObject.AlbumId = rs("AlbumId").ToString()
                    homePageObject.StoryTitle = rs("StoryTitle").ToString()
                    homePageObject.AlbumName = rs("AlbumName").ToString()
                    homePageObject.AlbumCover = rs("AlbumCover").ToString()
                    homePageObject.Votes = rs("Votes").ToString()
                    homePageObject.PictureId = rs("PictureId").ToString()
                    homePageObject.TableName = rs("tableName").ToString()
                    homePageObject.PageCount = CType(cmd.Parameters("@PageCount").Value, Integer)
                    homePageObject.Sort = Guid.NewGuid()
                    details.Add(homePageObject)
                    Next
            End Using
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        Dim js As New JavaScriptSerializer()
        Dim strJson As String = js.Serialize(details.ToArray)
        Return strJson
    End Function
4

1 回答 1

1

要随机化列表,您可以执行以下操作。(并且您不需要 in 的Sort属性HomePageObject来完成此操作)

Dim rnd As new Random()
Dim strJson As String = js.Serialize(details.OrderBy(Function(x) rnd.Next()).ToArray())
于 2013-01-01T19:20:08.523 回答