2012-11-08 3 views
0

SQL 호출로 .asmx 페이지에서 순수한 JSON을 얻으려고합니다. 그것을 얻을 수없는 것 같습니다. 내가 찾은 모든 게시물은 C# 또는 내가 뭘했는지 알지 못합니다. 직렬화로 인해 1 차원 배열 문제가 발생합니다. 작은 자바 응용 프로그램에 대한 내 웹 서버의 MS 액세스 데이터베이스에서 데이터를 가져와야합니다.JSON에 샘플 VB.NET 객체 필요

<%@ WebService class="GetDBStudent" %> 

Imports System.Web 
Imports System.Web.Services 
Imports System.Xml 
Imports System.Web.Services.Protocols 
Imports System.Web.Script.Services 
Imports System.Data 
imports System.Web.Script.Serialization 

'<System.Web.Script.Services.ScriptService()> _ 
<WebService(Namespace:="com.mcfrsit.GetDBStudent")> _ 
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ 
Public Class GetDBStudent 
Inherits System.Web.Services.WebService 
Public Class Students 
    Public StudentID As String 
    Public LastName As String 
    Public FirstName As String 
    Public Affiliation As String 
    Public ClassName As String 
    Public DateCompleted As DateTime 
End Class 

<WebMethod()> _ 
<ScriptMethod(UseHttpGet:=False, ResponseFormat:=ResponseFormat.Json)> _ 
Public Function GetArray() As Students() 

    ' Create a connection string 
    Dim DBConnection As String =  ConfigurationManager.ConnectionStrings("OdbcServices").ToString 
    Dim sql As String = "SELECT * FROM ClassRecordsEnrollmentsQry WHERE [Affiliation] = 'DFRS'" 
    Dim Conn As New ADODB.Connection() 
    Dim rs As New ADODB.Recordset() 

    Dim daTitles As New Data.OleDb.OleDbDataAdapter() 

    Dim dsTitles As New DataSet("CrossTab") 
    Conn.Open(DBConnection, "", "", -1) 

    Try 
     rs.Open(sql, DBConnection, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockBatchOptimistic, 1) 

     daTitles.Fill(dsTitles, rs, "Students") 
     'create object array, using row count as upper dim 
     Dim objStudents As Students() = New Students(dsTitles.Tables(0).Rows.Count - 1) {} 

     'loop through dataset to add data to object array 
     Dim intRsCount As Int16 
     For intRsCount = 0 To dsTitles.Tables(0).Rows.Count - 1 
      Dim intCsCount As Int16 
      For intCsCount = 0 To dsTitles.Tables(0).Columns.Count - 1 
       'Dim strColName As String = dsTitles.Tables(0).Columns(intCsCount) 
      Next 
      objStudents(intRsCount) = New Students 
      objStudents(intRsCount).StudentID = dsTitles.Tables(0).Rows(intRsCount)(0) 
      objStudents(intRsCount).LastName = dsTitles.Tables(0).Rows(intRsCount)(1) 
      objStudents(intRsCount).FirstName = dsTitles.Tables(0).Rows(intRsCount)(2) 
      objStudents(intRsCount).Affiliation = dsTitles.Tables(0).Rows(intRsCount)(3) 
      objStudents(intRsCount).ClassName = dsTitles.Tables(0).Rows(intRsCount)(4) 
      objStudents(intRsCount).DateCompleted = dsTitles.Tables(0).Rows(intRsCount)(5) 
     Next 

     'Return new JavaScriptSerializer().Serialize(objStudents) 
     Return objStudents 

    Catch ex As Exception 
     'Response.Write("Sorting is not supported in the view") 
    Finally 
     Conn.Close() 
    End Try 
End Function 


End Class 

답변

0

해결 : 상기

[{"text":"text2"}] 

왜 추가 "["와 "]"... 반환 함수 객체와 같은 미세 근무 JSON 문자열의 모양을 반환하지만

시작과 끝?

관련 문제