本文整理汇总了C#中Newtonsoft.Json.JsonReader.ReadAsInt32方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.ReadAsInt32方法的具体用法?C# JsonReader.ReadAsInt32怎么用?C# JsonReader.ReadAsInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonReader
的用法示例。
在下文中一共展示了JsonReader.ReadAsInt32方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadJson
/// <summary>
/// Reads the json.
/// </summary>
/// <param name="reader">The reader.</param>
/// <param name="objectType">Type of the object.</param>
/// <param name="existingValue">The existing value.</param>
/// <param name="serializer">The serializer.</param>
/// <returns>The object instance.</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
int? r = reader.ReadAsInt32();
int? g = reader.ReadAsInt32();
int? b = reader.ReadAsInt32();
int? a = reader.ReadAsInt32();
if (reader.Read() && r.HasValue && g.HasValue && b.HasValue && a.HasValue)
{
return new Color { R = (byte)r.Value, G = (byte)g.Value, B = (byte)b.Value, A = (byte)a.Value };
}
return existingValue;
}
示例2: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
int? value = reader.ReadAsInt32();
if (value == null)
return null;
return (TimeSpan?)TimeSpan.FromMilliseconds (value.Value * 100);
}
示例3: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
//reader.Read();
var obj = new Filter();
obj.Name = reader.ReadAsString();
obj.Count = reader.ReadAsInt32().GetValueOrDefault();
reader.Read();
return obj;
}
示例4: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
PocketArticles pocketArticles1 = new PocketArticles();
int? nullable;
while (reader.Read())
{
if (reader.Value != null)
{
switch (reader.Path)
{
case "status":
PocketArticles pocketArticles2 = pocketArticles1;
nullable = reader.ReadAsInt32();
int valueOrDefault1 = nullable.GetValueOrDefault();
pocketArticles2.Status = valueOrDefault1;
break;
case "complete":
PocketArticles pocketArticles3 = pocketArticles1;
nullable = reader.ReadAsInt32();
int valueOrDefault2 = nullable.GetValueOrDefault();
pocketArticles3.Complete = valueOrDefault2;
break;
case "list":
pocketArticles1.Articles = serializer.Deserialize<IEnumerable<IPocketArticle>>(reader);
break;
case "since":
PocketArticles pocketArticles4 = pocketArticles1;
nullable = reader.ReadAsInt32();
int valueOrDefault3 = nullable.GetValueOrDefault();
pocketArticles4.Since = valueOrDefault3;
break;
}
}
}
reader.Read();
return (object) pocketArticles1;
}
示例5: ReadJson
/// <summary>
/// Reads the JSON representation of the object.
/// </summary>
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
/// <param name="objectType">Type of the object.</param>
/// <param name="existingValue">The existing value of object being read.</param>
/// <param name="serializer">The calling serializer.</param>
/// <returns>The object value.</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader == null) throw new ArgumentNullException("reader");
if (objectType == null) throw new ArgumentNullException("objectType");
if (reader.TokenType == JsonToken.Null)
{
return null;
}
if (reader.TokenType != JsonToken.StartArray)
{
throw new JsonException(string.Format(CultureInfo.InvariantCulture, "Expected StartArray token not {0}", reader.TokenType));
}
var dt = existingValue as DataTable;
if (dt == null)
{
// handle typed datasets
dt = (objectType == typeof(DataTable))
? new DataTable()
: (DataTable)Activator.CreateInstance(objectType);
dt.Locale = CultureInfo.CurrentCulture;
}
var columnTypes = new List<DataType>();
reader.Read(); // Move from StartArray to StartObject
if (reader.TokenType != JsonToken.StartObject)
{
throw new JsonException(string.Format(CultureInfo.InvariantCulture, "Expected StartObject token not {0}", reader.TokenType));
}
reader.Read(); // move from StartObject to PropertyName
if (reader.TokenType != JsonToken.PropertyName)
{
throw new JsonException(string.Format(CultureInfo.InvariantCulture, "Expected PropertyName token not {0}", reader.TokenType));
}
while (reader.TokenType == JsonToken.PropertyName)
{
var columnName = (string)reader.Value;
reader.ReadAsInt32();
var dataType = (int)reader.Value;
dt.Columns.Add(new DataColumn(columnName, TypeFromDataType(dataType)));
columnTypes.Add((DataType)dataType);
reader.Read();
}
if (reader.TokenType != JsonToken.EndObject)
{
throw new JsonException(string.Format(CultureInfo.InvariantCulture, "Expected EndObject token not {0}", reader.TokenType));
}
reader.Read();
// If there are no rows in this table, we might actually be at the end of our object
// so just move on
if (reader.TokenType == JsonToken.StartArray)
{
while (reader.TokenType == JsonToken.StartArray)
{
var row = dt.NewRow();
for (int i = 0; i < dt.Columns.Count; i++)
{
ReadByDataType(reader, columnTypes[i]);
if (reader.TokenType == JsonToken.Null)
{
row[i] = DBNull.Value;
}
else
{
row[i] = reader.Value;
}
}
row.EndEdit();
dt.Rows.Add(row);
// We've finished reading all of the columns, so the next this we read should
//.........这里部分代码省略.........
示例6: ReadByDataType
private static void ReadByDataType(JsonReader reader, DataType dataType)
{
switch (dataType)
{
case DataType.String:
reader.ReadAsString();
break;
case DataType.Int16:
case DataType.Int32:
reader.ReadAsInt32();
break;
case DataType.ByteArray:
reader.ReadAsBytes();
break;
case DataType.Decimal:
reader.ReadAsDecimal();
break;
case DataType.DateTime:
reader.ReadAsDateTime();
break;
// These types are dealt with, but there's no explicit reader method for them
// so we just have to trust that it does the right thing.
case DataType.Byte:
case DataType.Int64:
case DataType.Boolean:
case DataType.Float:
case DataType.Double:
reader.Read();
break;
}
}
示例7: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var list = new List<IPocketArticle>();
var pocketArticle = new PocketArticle();
while (reader.Read())
{
if (reader.Value != null)
{
string[] strArray = reader.Path.Split('.');
switch (strArray[strArray.Count() - 1])
{
case "item_id":
pocketArticle.ItemId = reader.ReadAsString();
break;
case "resolved_id":
pocketArticle.ResolvedId = reader.ReadAsString();
break;
case "given_url":
pocketArticle.GivenUrl = reader.ReadAsString();
break;
case "given_title":
pocketArticle.GivenTitle = reader.ReadAsString();
break;
case "favorite":
pocketArticle.Favorite = reader.ReadAsString();
break;
case "status":
pocketArticle.Status = reader.ReadAsString();
break;
case "time_added":
pocketArticle.TimeAdded = reader.ReadAsString();
break;
case "time_updated":
pocketArticle.TimeUpdated = reader.ReadAsString();
break;
case "time_read":
pocketArticle.TimeRead = reader.ReadAsString();
break;
case "time_favorited":
pocketArticle.TimeFavorited = reader.ReadAsString();
break;
case "sort_id":
pocketArticle.SortId = reader.ReadAsInt32().GetValueOrDefault();
break;
case "resolved_title":
pocketArticle.ResolvedTitle = reader.ReadAsString();
break;
case "resolved_url":
pocketArticle.ResolvedUrl = reader.ReadAsString();
break;
case "excerpt":
pocketArticle.Excerpt = reader.ReadAsString();
break;
case "is_article":
pocketArticle.IsArticle = reader.ReadAsString();
break;
case "is_index":
pocketArticle.IsIndex = reader.ReadAsString();
break;
case "has_video":
pocketArticle.HasVideo = reader.ReadAsString();
break;
case "has_image":
pocketArticle.HasImage = reader.ReadAsString();
break;
case "word_count":
pocketArticle.WordCount = reader.ReadAsString();
break;
}
}
else
{
if (!string.IsNullOrEmpty(pocketArticle.ItemId))
list.Add(pocketArticle);
pocketArticle = new PocketArticle();
}
}
return list;
}
示例8: ReadForType
private bool ReadForType(JsonReader reader, JsonContract contract, bool hasConverter)
{
if (hasConverter)
return reader.Read();
switch (contract != null ? (int) contract.InternalReadType : 0)
{
case 0:
while (reader.Read())
{
if (reader.TokenType != JsonToken.Comment)
return true;
}
return false;
case 1:
reader.ReadAsInt32();
break;
case 2:
reader.ReadAsBytes();
break;
case 3:
reader.ReadAsString();
break;
case 4:
reader.ReadAsDecimal();
break;
case 5:
reader.ReadAsDateTime();
break;
default:
throw new ArgumentOutOfRangeException();
}
return reader.TokenType != JsonToken.None;
}
示例9: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var corner = new TerrainCorner();
if (reader.TokenType != JsonToken.StartArray) return new TerrainCorner?();
corner.TopLeft = reader.ReadAsInt32() ?? 0;
corner.TopRight = reader.ReadAsInt32() ?? 0;
corner.BottomLeft = reader.ReadAsInt32() ?? 0;
corner.BottomRight = reader.ReadAsInt32() ?? 0;
reader.Read();
if (reader.TokenType != JsonToken.EndArray) return new TerrainCorner?();
return corner;
}
示例10: ReadJson
/// <summary>
/// Reads the JSON representation of the object.
/// </summary>
/// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader" /> to read from.</param>
/// <param name="objectType">Type of the object.</param>
/// <param name="existingValue">The existing value of object being read.</param>
/// <param name="serializer">The calling serializer.</param>
/// <returns>
/// The object value.
/// </returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
ActionBase action = null;
var condition = Condition.Equals;
var actionName = string.Empty;
var path = string.Empty;
var value = string.Empty;
var text = string.Empty;
var expectedValue = string.Empty;
var expectedText = string.Empty;
var seconds = 0;
while (reader.Read() && reader.TokenType != JsonToken.EndObject)
{
if (reader.TokenType == JsonToken.PropertyName)
{
switch (reader.Value as string)
{
case "action":
actionName = reader.ReadAsString();
break;
case "path":
path = reader.ReadAsString();
break;
case "value":
value = reader.ReadAsString();
break;
case "text":
text = reader.ReadAsString();
break;
case "expectedValue":
expectedValue = reader.ReadAsString();
break;
case "expectedText":
expectedText = reader.ReadAsString();
break;
case "condition":
condition = (Condition)Enum.Parse(typeof (Condition), reader.ReadAsString(), true);
break;
case "seconds":
seconds = reader.ReadAsInt32() ?? 10;
break;
}
}
}
switch (actionName)
{
case "click":
action = new ClickAction { Condition = condition, Path = path, Text = text, Value = value };
break;
case "enterKey":
action = new EnterKeyAction { Condition = condition, Path = path, Text = text, Value = value };
break;
case "navigateTo":
action = new NavigateToAction { Path = path };
break;
case "selectItem":
action = new SelectItemAction { Condition = condition, Path = path, Text = text, Value = value };
break;
case "setText":
action = new SetTextAction { Path = path, Value = value };
break;
case "test":
action = new TestAction { Condition = condition, Path = path, ExpectedText = expectedText, ExpectedValue = expectedValue };
break;
case "wait":
action = new WaitAction { Seconds = seconds };
break;
}
return action;
}
示例11: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var result = new UTorrentTorrent();
result.Hash = reader.ReadAsString();
result.Status = (UTorrentTorrentStatus)reader.ReadAsInt32();
result.Name = reader.ReadAsString();
reader.Read();
result.Size = (long)reader.Value;
result.Progress = (int)reader.ReadAsInt32() / 1000.0;
reader.Read();
result.Downloaded = (long)reader.Value;
reader.Read();
result.Uploaded = (long)reader.Value;
result.Ratio = (int)reader.ReadAsInt32() / 1000.0;
result.UploadSpeed = (int)reader.ReadAsInt32();
result.DownloadSpeed = (int)reader.ReadAsInt32();
result.Eta = (int)reader.ReadAsInt32();
result.Label = reader.ReadAsString();
result.PeersConnected = (int)reader.ReadAsInt32();
result.PeersInSwarm = (int)reader.ReadAsInt32();
result.SeedsConnected = (int)reader.ReadAsInt32();
result.SeedsInSwarm = (int)reader.ReadAsInt32();
result.Availablity = (int)reader.ReadAsInt32() / 65536.0;
result.TorrentQueueOrder = (int)reader.ReadAsInt32();
reader.Read();
result.Remaining = (long)reader.Value;
reader.Read();
// Builds before 25406 don't return the remaining items.
if (reader.TokenType != JsonToken.EndArray)
{
result.DownloadUrl = (string)reader.Value;
reader.Read();
result.RssFeedUrl = reader.Value;
reader.Read();
result.StatusMessage = reader.Value;
reader.Read();
result.StreamId = reader.Value;
reader.Read();
result.DateAdded = reader.Value;
reader.Read();
result.DateCompleted = reader.Value;
reader.Read();
result.AppUpdateUrl = reader.Value;
result.RootDownloadPath = reader.ReadAsString();
reader.Read();
result.Unknown27 = reader.Value;
reader.Read();
result.Unknown28 = reader.Value;
while(reader.TokenType != JsonToken.EndArray)
reader.Read();
}
return result;
}
示例12: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
{
List<Vector3> points = new List<Vector3>();
reader.Read();
int seed = (int)reader.ReadAsInt32();
reader.Read();
reader.Read();
reader.Read();
while (reader.TokenType != JsonToken.EndArray)
{
float x = (float)reader.ReadAsDecimal();
float y = (float)reader.ReadAsDecimal();
float z = (float)reader.ReadAsDecimal();
points.Add(new Vector3(x, y, z));
reader.Read();
reader.Read();
}
reader.Read();
return new PointSet(points.ToArray(), seed);
}