1. byte[] buffer=new byte[]{0x73,0x68,0x61,0x6E,0x67,0x67,0x75,0x61};//03 00 08 73 68 61 6E 67 67 75 61  
  2. string str=System.Text.Encoding.UTF8.GetString(buffer); 

3.Object在.net中对应的就是Hashtable,内容由UTF8字符串作为Key,其他AMF协议类型作为Value,该对象由3个字节:00 00 09来表示结束。C#中读取该对象使用如下方法:

  1. private Hashtable ReadUntypedObject()  
  2. { Hashtable hash = new Hashtable();  
  3.  string key = ReadShortString();  
  4.  for (byte type = ReadByte(); type != 9; type = ReadByte())  
  5.  {hash.Add(key, ReadData(type));  
  6. key = ReadShortString(); }  
  7.  return hash;}  

4.Null就是空对象,该对象只占用一个字节,那就是Null对象标识0x05。

5. Undefined 也是只占用一个字节0x06。

6.MixedArray相当于Hashtable,与3不同的是该对象定义了Hashtable的大小。读取该对象的C#代码是:

  1. private Hashtable ReadDictionary()  
  2. { int size = ReadInt32();  
  3.  Hashtable hash = new Hashtable(size);  
  4.  string key = ReadShortString();  
  5.  for (byte type = ReadByte(); type != 9; type = ReadByte())  
  6.  {object value = ReadData(type);  
  7. hash.Add(key, value);  
  8. key = ReadShortString(); }  
  9.  return hash;} 


相关内容