01
<script language=
"JScript"
runat=
"server"
>
02
function getJSon(str){
03
try{
04
eval(
"var JSonStr = ("
+ str +
")"
);
05
}catch(ex){
06
var JSonStr = null;
07
}
08
return JSonStr;
09
}
10
</script>
11
<%
12
set obj = getJSon(
"{name:'anlige'}"
)
13
response.write obj.name
14
%>
(鼠標移到代碼上去,在代碼的頂部會出現四個圖標,第一個是查看源代碼,第二個是復制代碼,第三個是打印代碼,第四個是幫助)
多條記錄的JSon對象的處理方法:
01
<script language=
"JScript"
runat=
"server"
>
02
Array.prototype.get = function(i)
03
{
04
return this[i];
05
};
06
function getJSon(str){
07
try{
08
eval(
"var JSonStr = ("
+ str +
")"
);
09
}catch(ex){
10
var JSonStr = null;
11
}
12
return JSonStr;
13
}
14
</script>
15
<%
16
str=
"{"
"postPrice"
":[{"
"Productid"
":1,"
"Productname"
": "
"手機"
","
"Price"
":25.5,"
"num"
": 1000,"
"url"
":"
"http://www.baidu.com"
"},{"
"Productid"
":2,"
"Productname"
": "
"相機"
","
"Price"
":75,"
"num"
": 2000,"
"url"
":"
"http://www.ASPbc.com"
"}]}"
17
str=right(str,len(str)-instr(str,
"["
)+1)
18
str=left(str,InstrRev(str,
"]"
))
19
dim obj
20
set obj = getJSon(str)
21
str0=
""
22
for i=0 to obj.length-1
23
str0=str0&
"ID="
&obj.get(i).productid&
"<br>"
24
str0=str0&
"ProductName="
&obj.get(i).Productname&
"<br>"
25
str0=str0&
"Price="
&obj.get(i).Price&
"元<br>"
26
str0=str0&
"num="
&obj.get(i).num&
"台<br>"
27
str0=str0&
"url="
&obj.get(i).url&
"<br><br>"
28
next
29
response.write str0
30
31
%>
(鼠標移到代碼上去,在代碼的頂部會出現四個圖標,第一個是查看源代碼,第二個是復制代碼,第三個是打印代碼,第四個是幫助)