asp的序列化操作与反序列化操作

serialize.asp

<%   
  '-------------------------------------------'   
  ' @title : de/serialize objects in vbscript '   
  ' @author: Peter Bucher             '   
  ' @orgin : Switzerland              '   
  '                           '   
  ' @licence: use for free            '   
  '                       '   
  ' description:                                           '   
  ' s_obj = string of the object name example: "myobject"  '   
  ' obj   = letter of the object name example:  myobject   '   
  '-------------------------------------------'   
%>   
<script language="jscript" runat="server">   
// List PropertyNames   
function listPropertyNames(Obj) {   
  var Names = "";   
  for (var I in Obj) {    
    Names += I + ";next;";   
    response.write (Names);   
  }   
  return Names;   
}   
</script>   
  
<%   
'// Serialize Function   
  Function Serialize(obj, s_obj)   
    Dim i_counter, _   
        a_names, _   
        i_ubound   
           
    a_names  = Split(listPropertyNames(obj), ";next;")   
    i_ubound = UBound(a_names)   
       
    Dim a_session()   
    Redim a_session(i_ubound, i_ubound)        
    For i_counter = 0 To UBound(a_names) -1   
        a_session(i_counter, 0) = a_names(i_counter)   
        a_session(i_counter, 1) = Eval(s_obj & "." & a_names(i_counter))   
    Next  
       
    'response.write a_session   
       
    Session(s_obj) = a_session   
  End Function  
%>   
  
  
  
  
<%   
  '// DeSerialize Function   
  Function DeSerialize(s_obj)   
    Dim a_names_and_values, _   
        y_counter   
       
    a_2 = Session(s_obj)   
    For y_counter = 0 To UBound(a_2) -1   
        Execute(s_obj & "." & a_2(y_counter, 0) & " = """ & a_2(y_counter, 1) & """")   
    Next  
  End Function  
%>   
<%   
'// Test Class   
Class MyClass  
 Dim m_MyProp   
  
 Public Property Get MyProp   
  MyProp = m_MyProp   
 End Property  
  
 Public Property Let MyProp(newText)   
  m_MyProp = newText   
 End Property  
  
End Class  
%>  

 

 

test1.asp

<!-- #include file="serialize.asp" --><br/><%<br/>Set c = New MyClassc.MyProp = "sdfasfasdfasd"<br/>Call Serialize(c, "c")<br/>set a = Server.CreateObject("Template.Test")<br/>a.fff(session("c"))<br/>%>   
<a href="test2.asp" title"go on">go on page 2</a>

 

 

test2.asp

<!-- #include file="serialize.asp" -->   
<%   
Set c = New MyClass  
Call DeSerialize("c")   
Response.Write c.myprop   
%>   
<a href="test1.asp" title="go on">go on page 1</a><br/>

 

你可能感兴趣的:(C++,c,C#,asp,Go)