當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
ASP生成JSON数据
生活随笔
收集整理的這篇文章主要介紹了
ASP生成JSON数据
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
原文地址為:
ASP生成JSON數(shù)據(jù)
< %@LANGUAGE = " VBSCRIPT " ?CODEPAGE = " 65001 " % >
< ! -- #include?file = " json.asp " -->
< ! -- #include?file = " inc/Conn.asp " ? -->
< %
response.ContentType = " text/json "
dim ?j
' 多重嵌套的JSON,要使用Dictionary才能實現(xiàn)
set ?j = new ?json
j.toResponse = false
set ?r = server.createobject( " scripting.dictionary " )
set ?b = server.createobject( " scripting.dictionary " )
set ?c = server.createobject( " scripting.dictionary " )
c.add? " x " , 5
c.add? " y " , 6
c.add? " z " , 11
b.add? " event " , " Mouse?Click "
b.add? " data " ,c
r.add? " success " , true
r.add? " result " ,b
a = j.toJSON( empty ,r, false )
response.write?a
' 記錄集轉(zhuǎn)為Json
set ?i = new ?json
i.toresponse = false
set ?rs = server.CreateObject( " adodb.recordset " )
sqlstr = " select?top?5?*?from?producttype "
rs.open?sqlstr,conn, 0 , 1
v = i.toJson( " result " ,rs, false )
rs.close
response.write?v
% >
轉(zhuǎn)載請注明本文地址: ASP生成JSON數(shù)據(jù)
< %@LANGUAGE = " VBSCRIPT " ?CODEPAGE = " 65001 " % >
< ! -- #include?file = " json.asp " -->
< ! -- #include?file = " inc/Conn.asp " ? -->
< %
response.ContentType = " text/json "
dim ?j
' 多重嵌套的JSON,要使用Dictionary才能實現(xiàn)
set ?j = new ?json
j.toResponse = false
set ?r = server.createobject( " scripting.dictionary " )
set ?b = server.createobject( " scripting.dictionary " )
set ?c = server.createobject( " scripting.dictionary " )
c.add? " x " , 5
c.add? " y " , 6
c.add? " z " , 11
b.add? " event " , " Mouse?Click "
b.add? " data " ,c
r.add? " success " , true
r.add? " result " ,b
a = j.toJSON( empty ,r, false )
response.write?a
' 記錄集轉(zhuǎn)為Json
set ?i = new ?json
i.toresponse = false
set ?rs = server.CreateObject( " adodb.recordset " )
sqlstr = " select?top?5?*?from?producttype "
rs.open?sqlstr,conn, 0 , 1
v = i.toJson( " result " ,rs, false )
rs.close
response.write?v
% >
?
面要注意的是:
1,嵌套的JSON是要用DICTIONARY來生成的,其他的方法,我還沒有找到
2,最終的結果在輸出時,可以用toJson(empty,r,false)這種形式,這樣,生成的JSON,就不會類似{var:{var1:'',var2:''}}這種形式,而是直接的:{var1:'',var2:''},這種格式在我們用來處理表單,返回數(shù)據(jù)時,一定要注意
3,生成JSON的ASP頁面,輸出格式,解析JSON的JS文件,HTML頁面,必須全是UTF-8格式編碼,一個環(huán)節(jié)編碼不正確,就會導致接收到的JSON在顯示中文時變亂碼
轉(zhuǎn)載請注明本文地址: ASP生成JSON數(shù)據(jù)
總結
以上是生活随笔為你收集整理的ASP生成JSON数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 鸿蒙芯片是华为公司靠几年造出来的,难度不
- 下一篇: SpringBoot学习-用户注册登录