2013-01-07 2 views
0

은 내가 이렇게 보이는 웹 서비스에서 일부 데이터를 반환해야합니다vb.net은 여러 유형의 json 객체를 반환합니까?

data.page = 1 
data.count = 12883 
data.rows(0).id = 1 
data.rows(0).name = "bob" 
data.rows(1).id = 2 
data.rows(1).name = "steve" 
data.rows(2).id = 3 
data.rows(2).name = "fred" 

나는이 작업을 수행하는 방법을 모르겠어요. 간단한 유형과 단순한 배열을 returend했지만이 같은 객체는 없었습니다.

데이터 원본은 SQL 데이터베이스입니다. 대상은 javascript/ajax 함수입니다. 현재 데이터 집합으로 행 자체를 성공적으로 반환하고 있지만 작동하지만 몇 가지 다른 "부모 수준"변수를 추가해야합니다. 전체 공개를 위해서

, 여기에 작동되는 코드입니다 :

<WebMethod()> _ 
Public Function rptPendingServerRequests() As DataSet 
    Dim connetionString As String 
    Dim connection As SqlConnection 
    Dim command As SqlCommand 
    Dim adapter As New SqlDataAdapter 
    Dim ds As New DataSet 
    Dim sql As String 

    connetionString = "..." 
    sql = "SELECT usm_request.request_id, usm_request.status, usm_request.req_by_user_id " + 
     "FROM usm_request " + 
     "WHERE usm_request.request_id in " + 
     "(SELECT distinct(usm_request.request_id) from usm_request, usm_subscription_detail WHERE usm_request.request_id = usm_subscription_detail.request_id " + 
     "AND usm_subscription_detail.offering_id = 10307) ORDER BY usm_request.request_id DESC" 
    connection = New SqlConnection(connetionString) 

    Try 
     connection.Open() 
     command = New SqlCommand(sql, connection) 
     adapter.SelectCommand = command 
     adapter.Fill(ds) 
     adapter.Dispose() 
     command.Dispose() 
     connection.Close() 

     Return ds 

    Catch ex As Exception 
    End Try 
End Function 

을 그리고 FlexiGrid 그것을 소비하는 것을 시도하고있다. 나는 운 좋게도 몇 시간 동안 그 일을 해왔다. 나는 기본적으로

http://code.google.com/p/flexigrid/wiki/TutorialPropertiesAndDocumentation

답변

1

난 당신이 단지 두 개의 클래스를 만들고이 클래스에 데이터베이스에서 데이터를 이동 오프 훨씬 더 좋을 것이라고 생각을 .NET으로 다음 사이트에서 PHP를 변환해야합니다. 예를 들어 :

Public Class MyDataClass 
    Public Property Page As Integer 

    Public ReadOnly Property Count As Integer 
     Get 
      If Me.Rows IsNot Nothing Then 
       Return Me.Rows.Count 
      Else 
       Return 0 
      End If 
     End Get 
    End Property 

    Public Property Rows As List(Of MyDataRow) 

    ' Parameterless constructor to support serialization. 
    Public Sub New() 
     Me.Rows = New List(Of MyDataRow) 
    End Sub 
    Public Sub New(wPage As Integer, ds As DataSet) 
     Me.New() 

     Me.Page = wPage 

     For Each oRow As DataRow In ds.Tables(0).Rows 
      Dim oMyRow As New MyDataRow 

      oMyRow.Id = oRow("id") 
      oMyRow.Name = oRow("Name") 

      Me.Rows.Add(oMyRow) 
     Next 
    End Sub 
End Class 

Public Class MyDataRow 
    Public Property Id As Integer 
    Public Property Name As String 

    ' Parameterless constructor to support serialization 
    Public Sub New() 

    End Sub 
End Class 

그런 다음 MyDataClass에 메소드의 리턴 타입을 변경하고 복귀 변경 : 나는 함수 선언을 변경하면

 Return New MyDataClass(1, ds) 
+0

을에 나는이 얻을 "MyDataClass으로": "CatRep합니다. reportdata.MyDataClass 매개 변수없는 생성자가 없기 때문에 serialize 할 수 없습니다. " –

+1

@ScottBeeson : 죄송합니다. 잊어 버렸습니다. 생성자를 포함하고 행이 추가되지 않는 문제를 해결할 수있는 대답을 업데이트했습니다. –

+0

달콤한, 좋아 보인다! 정말 고마워. 그것은 영원한 멍청한 되 고 힘들어요 :) –

관련 문제