티스토리 뷰

개발

classic asp with json

Hello™ 2019. 2. 2. 20:36

json2.zip



json으로 데이터를 받아와서 사용하는 일이 계속 있음

데이터를 만드는건 Response.Write "어쩌고" 로 만들면 되는데 받아오는 값을 처리해야지 될때가 문제임



{"status":0,"studentdata":[{"cName":"어쩌고 저쩌고","cID":120,"stdID":12120,"stdName":"난이름","phonenumber":"010-0000-1111"},{"cName":"어쩌고 저쩌고","cID":120,"stdID":12121,"stdName":"난이름2","phonenumber":"010-0000-2222"}]}



이렇게

{

로 시작해서 상태값이 있고

[{

로 내용을 시작하는 경우에는 그냥 불러와서 처리하면 됨

어떻게?






<!--#include virtual="/json2.asp"-->

이렇게 인클루드 하고





urlPath = "통신할 URL, http까지 다 써야지 됨"


strSendData = "{" & vbCrLf

strSendData = strSendData & "  ""token"": ""파라미터값이 있을경우1""," & vbCrLf

strSendData = strSendData & "  ""token2"": ""파라미터값이 있을경우2""" & vbCrLf

strSendData = strSendData & "}" & vbCrLf


' 데이터 보내기 & JSON 데이타 가져오기

Set objHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")

objHttp.Open "POST", urlPath, False

objHttp.setRequestHeader "Content-Type", "application/json;charset=utf-8"

objHttp.setRequestHeader "reqVersion", "2"

objHttp.Send strSendData

'objHttp.Send ""    ' 이건 파라미터가 없을경우 이거나, get으로 할경우 URL에 쭉 파라미터 적으면 됨.

result = objHttp.responseText

Set objHttp = Nothing




Set jResult = JSON.parse(join(array(result)))


'여기에 내용

If jResult.status = "0" Then            ' 이건 첫번째 상태값이 있는 것일경우 바로 가져옴


str_cName = Trim(jResult.studentdata.Get(0).cName)

이렇게 이름으로 가져오면 됨


str_cID = Trim(jResult.studentdata.Get(0).cID)


Else


End If

'//여기에 내용


Set jResult = Nothing





만일 데이터 타입이 { 로 시작 [{ 형태가 아닌

{ 로 시작 { 로 컨텐트를 구분할 경우에는


strSendData = "{" & vbCrLf

strSendData = strSendData & "  ""success"": 1," & vbCrLf

strSendData = strSendData & "  ""error"": """"," & vbCrLf

strSendData = strSendData & "  ""userItem"": " & vbCrLf

strSendData = strSendData & "    {" & vbCrLf

strSendData = strSendData & " ""email"": ""admin@email.com""," & vbCrLf

strSendData = strSendData & " ""bookCode"": ""studium""," & vbCrLf

strSendData = strSendData & " ""shipperCode"": ""studium.ai""," & vbCrLf

strSendData = strSendData & " ""shipperCall"": ""세번째 텍트스""," & vbCrLf

strSendData = strSendData & " ""shipperAddress"": ""내용이 많은 텍스트일경우에는 어떻게 다 들어오는지""," & vbCrLf

strSendData = strSendData & " ""saleSiteCode"": ""12345""" & vbCrLf

strSendData = strSendData & "    }" & vbCrLf

strSendData = strSendData & "  " & vbCrLf

strSendData = strSendData & "}" & vbCrLf




위와 동일하게 작성하고 가져올때 get(0) 빼고 아래처럼 바로 key로처리

str_email = Trim(jResult.userItem.email)










============================= json2 정보

AXE(ASP Xtreme Evolution) JSON parser based on Douglas Crockford json2.js.


This class is the result of Classic ASP JSON topic revisited by Fabio Zendhi

Nagao (nagaozen). JSON2.ASP is a better option over JSON.ASP because it embraces

the AXE philosophy of real collaboration over the languages. It works under the

original json parser, so this class is strict in the standard rules, it also

brings more of the Javascript json feeling to other ASP languages (eg. no more

oJson.getElement("foo") stuff, just oJson.foo and you get it).


License:


This file is part of ASP Xtreme Evolution.

Copyright (C) 2007-2012 Fabio Zendhi Nagao


ASP Xtreme Evolution is free software: you can redistribute it and/or modify

it under the terms of the GNU Lesser General Public License as published by

the Free Software Foundation, either version 3 of the License, or

(at your option) any later version.


ASP Xtreme Evolution is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

GNU Lesser General Public License for more details.


You should have received a copy of the GNU Lesser General Public License

along with ASP Xtreme Evolution. If not, see <http://www.gnu.org/licenses/>.

============================= //json2 정보