コード例 #1
0
 public static void Deserialise(this PageInfo pageInfo, JsonReader reader)
 {
     if (reader.Read() && reader.State == TJsonReaderState.Object)
     {
         //Link link = null;
         while (reader.Read() && reader.State != TJsonReaderState.EndObject)
         {
             switch (reader.State)
             {
                 case TJsonReaderState.Member:
                     string elementName = reader.Text;
                     reader.Read();
                     int value;
                     if (int.TryParse(reader.Text, out value))
                     {
                         switch (elementName)
                         {
                             case "TotalCount":
                                 pageInfo.TotalCount = value;
                                 break;
                             case "ItemsCount":
                                 pageInfo.ItemsCount = value;
                                 break;
                             case "StartIndex":
                                 pageInfo.StartIndex = value;
                                 break;
                         }
                     }
                     break;
                 default:
                     break;
             }
         }
     }
 }
コード例 #2
0
 public static void Deserialise(this List<Link> links, JsonReader reader)
 {
     if (reader.Read() && reader.State == TJsonReaderState.Array)
     {
         Link link = null;
         while (reader.Read() && reader.State != TJsonReaderState.EndArray)
         {
             switch (reader.State)
             {
                 case TJsonReaderState.Object:
                     link = new Link();
                     links.Add(link);
                     break;
                 case TJsonReaderState.Member:
                     string attribute = reader.Text;
                     reader.Read();
                     if (string.Compare(attribute, "rel", true) == 0)
                         link.rel = reader.Text;
                     else if (string.Compare(attribute, "href", true) == 0)
                         link.href = reader.Text;
                     else
                         throw new NotSupportedException("Unsupported attribute: " + attribute);
                     break;
                 default:
                     break;
             }
         }
     }
 }