王新阳

wangxinyang

asp用服务器端js解析并获取简单json示例

<script type="text/javascript" language="javascript" runat="server">
function jsParseJSON(s){
	try{return (new Function('return' + s))(); }catch(e){return false};
}
function jsGetField(s, fld){
	var obj=jsParseJSON(s);
	return obj===false ? '' : (typeof obj[fld]==='undefined' ? '' : obj[fld]);
}
</script>
<%
	Response.Write jsGetField("{""err"":0,""msg"":""ok""}", "msg")
%>
输出结果:ok
2015-07-22
2024-11-23 星期六 农历十月二十三