프로그래밍/ASP

asp JSON Parser 사용

p-a-r-k 2015. 2. 26. 10:11
반응형

<%
   Response.AddHeader "Content-Type", "application/json"

    'DB 연결
	SbDBConn objConn

   sData = "{""date"":[""2015-02-26""], ""data"":["_
			& "{""ID"":""test01"",""NAME"":""홍길동""},{""ID"":""test02"",""NAME"":""보리""}]}"
	'request.form("DATA")
   
   Set sData = JSON.parse(sData)

   nCnt = 0
   itemCnt = sData.data.length
   sSalesDay = sData.date

   For Each o In sData.data
      Set objCmd = Server.CreateObject("ADODB.Command")
      With objCmd
         .ActiveConnection = objConn
         .CommandType = adCmdStoredProc
         .CommandText = "USP_TEST"
         .Parameters.Append .CreateParameter("RETURN_VALUE", adInteger, adParamReturnValue)
         .Parameters.Append .CreateParameter("@sId", adVarchar, adParamInput, 12, o.ID)
         .Parameters.Append .CreateParameter("@sName", adVarchar, adParamInput, 100, o.NAME)
         .Execute , , adExecuteNoRecords
         nRetValue	= .Parameters("RETURN_VALUE")
      End With
      Set objCmd = Nothing

      If nRetValue = "1" Then
         nCnt = nCnt + 1
         IF nCnt = itemCnt THEN
            sJsonText = "{'RESULT':'Y'}"
         ELSE
            sJsonText = "{'RESULT':'T'}"
         END IF
      Else 
         sJsonText = "{'RESULT':'E'}"
      End If

   Next

   'sJsonText = "{'data':'"& sData.data.length &"'}"
	sJsonText = Replace(sJsonText,"'",Chr(34))
	Response.write sJsonText
   
   SbDbClose objConn
%>
반응형