本文整理汇总了C#中Newtonsoft.Json.JsonReader.ReadAsString方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.ReadAsString方法的具体用法?C# JsonReader.ReadAsString怎么用?C# JsonReader.ReadAsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonReader
的用法示例。
在下文中一共展示了JsonReader.ReadAsString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
string displayName = string.Empty;
string address = string.Empty;
while (reader.Read())
{
var tokenType = reader.TokenType;
if (reader.TokenType == JsonToken.PropertyName)
{
var val = (reader.Value as string )?? string.Empty;
if (val == "DisplayName")
{
displayName = reader.ReadAsString();
}
if (val == "Address")
{
address = reader.ReadAsString();
}
}
if (reader.TokenType == JsonToken.EndObject)
{
break;
}
}
var mailAddress = new MailAddress(address, displayName);
return mailAddress;
}
示例2: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
return null;
reader.Assert(JsonToken.StartObject);
string toString = null;
string idObj = null;
string typeStr = null;
Entity entity = null;
reader.Read();
while (reader.TokenType == JsonToken.PropertyName)
{
switch ((string)reader.Value)
{
case "toStr": toString = reader.ReadAsString(); break;
case "id": idObj = reader.ReadAsString(); break;
case "EntityType": typeStr = reader.ReadAsString(); break;
case "entity":
reader.Read();
entity = (Entity)serializer.Deserialize(reader, typeof(Entity));
break;
default: throw new InvalidOperationException("unexpected property " + (string)reader.Value);
}
reader.Read();
}
reader.Assert(JsonToken.EndObject);
Type type = TypeLogic.GetType(typeStr);
PrimaryKey? idOrNull = idObj == null ? (PrimaryKey?)null : PrimaryKey.Parse(idObj, type);
if (entity == null)
return Lite.Create(type, idOrNull.Value, toString);
var result = entity.ToLiteFat(toString);
if (result.EntityType != type)
throw new InvalidOperationException("Types don't match");
if (result.IdOrNull != idOrNull)
throw new InvalidOperationException("Id's don't match");
var existing = existingValue as Lite<Entity>;
if (existing.Is(result) && existing.EntityOrNull == null && result.EntityOrNull != null)
{
existing.SetEntity(result.EntityOrNull);
return existing;
}
return result;
}
示例3: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
Debugger.Break();
Source source = new Source();
source.Format = reader.ReadAsString();
source.Header = reader.ReadAsString();
source.Link = reader.ReadAsString();
return source;
}
示例4: ReadJson
/// <summary>
/// Reads the JSON representation of the object.
/// </summary>
public override object ReadJson( JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer )
{
if( typeof( DataCharacteristic ) == objectType )
{
var characteristic = new DataCharacteristic();
if( reader.Read() && reader.TokenType == JsonToken.PropertyName )
{
characteristic.Uuid = new Guid( (string)reader.Value );
var valueAttributes = new System.Collections.Generic.List<DataService.Attribute>();
if( reader.Read() && reader.TokenType == JsonToken.StartObject )
{
while( reader.Read() && reader.TokenType == JsonToken.PropertyName )
{
var key = ushort.Parse( reader.Value.ToString(), System.Globalization.CultureInfo.InvariantCulture );
var value = reader.ReadAsString();
valueAttributes.Add( new DataService.Attribute( key, value ) );
}
}
characteristic.Value = new DataValue( valueAttributes.ToArray() );
}
return characteristic;
}
else
{
var characteristics = new System.Collections.Generic.List<DataCharacteristic>();
while( reader.Read() && reader.TokenType == JsonToken.PropertyName )
{
var characteristic = new DataCharacteristic();
characteristic.Uuid = new Guid( (string) reader.Value );
var valueAttributes = new System.Collections.Generic.List<DataService.Attribute>();
if( reader.Read() && reader.TokenType == JsonToken.StartObject )
{
while( reader.Read() && reader.TokenType == JsonToken.PropertyName )
{
var key = ushort.Parse( reader.Value.ToString(), System.Globalization.CultureInfo.InvariantCulture );
var value = reader.ReadAsString();
valueAttributes.Add( new DataService.Attribute( key, value ) );
}
}
characteristic.Value = new DataValue( valueAttributes.ToArray() );
characteristics.Add( characteristic );
}
return characteristics.ToArray();
}
}
示例5: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if( reader.TokenType == JsonToken.Null )
{
return null;
}
if( reader.TokenType != JsonToken.StartObject )
{
var msg = string.Join(" ",
$"The JSON representation of binary data (byte[]) when parsing the server response is not a {Converter.PseudoTypeKey}:{Converter.Binary} object.",
$"This happens if your JSON document contains binary data (byte[]) in some other format (like a base64 string only) rather than a native RethinkDB pseudo type {Converter.PseudoTypeKey}:{Converter.Binary} object.",
$"If you are overriding the default Ser/Deserialization process, you need to make sure byte[] is a native {Converter.PseudoTypeKey}:{Converter.Binary} objects before using the built-in {nameof(ReqlBinaryConverter)}.",
"See https://rethinkdb.com/docs/data-types/ for more information about how binary data is represented in RethinkDB.");
throw new JsonSerializationException(msg);
}
reader.ReadAndAssertProperty(Converter.PseudoTypeKey);
var reql_type = reader.ReadAsString();
if( reql_type != Converter.Binary )
{
throw new JsonSerializationException($"Expected {Converter.PseudoTypeKey} should be {Converter.Binary} but got {reql_type}.");
}
reader.ReadAndAssertProperty("data");
var data = reader.ReadAsBytes();
//realign and get out of the pseudo type
//one more post read to align out of { reql_type:BINARY, data:""}
reader.ReadAndAssert();
return data;
}
示例6: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var filter = new TermsQueryDescriptor<object>();
ITermsQuery f = filter;
if (reader.TokenType != JsonToken.StartObject)
return null;
var depth = reader.Depth;
while (reader.Read() && reader.Depth >= depth && reader.Value != null)
{
var property = reader.Value as string;
switch (property)
{
case "boost":
reader.Read();
f.Boost = reader.Value as double?;
break;
case "_name":
f.Name = reader.ReadAsString();
break;
default:
f.Field = property;
//reader.Read();
ReadTerms(f, reader, serializer);
//reader.Read();
break;
}
}
return filter;
}
示例7: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var str = string.Empty;
if (reader.TokenType != JsonToken.Null && reader.TokenType == JsonToken.String)
str = reader.ReadAsString();
return NamingConvention.FromString(str);
}
示例8: ReadJson
/// <summary>
/// Reads the JSON representation of the object.
/// </summary>
/// <param name="reader">The <see cref="Newtonsoft.Json.JsonReader"/> to read from.</param>
/// <param name="objectType">The <see cref="System.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)
{
switch(reader.TokenType)
{
case JsonToken.Integer:
return new Contributors { Id = (long)reader.Value };
case JsonToken.StartObject:
reader.Read();
var value = new Contributors();
while(reader.TokenType != JsonToken.EndObject)
{
if(reader.TokenType != JsonToken.PropertyName)
throw new FormatException("The format of this object is wrong");
switch((string)reader.Value)
{
case "id":
value.Id = (long)reader.ReadAsDecimal();
break;
case "screen_name":
value.ScreenName = reader.ReadAsString();
break;
default:
reader.Read();
break;
}
reader.Read();
}
return value;
}
throw new InvalidOperationException("This object is not a Contributors");
}
示例9: DeserializeFromPackageJson
public static DubProjectConfiguration DeserializeFromPackageJson(JsonReader j)
{
var c = new DubProjectConfiguration { Name = "<Undefined>" };
var srz = new JsonSerializer();
while (j.Read() && j.TokenType != JsonToken.EndObject)
{
if (j.TokenType == JsonToken.PropertyName)
{
switch (j.Value as string)
{
case "name":
c.Name = c.Id = j.ReadAsString();
break;
case "platforms":
j.Read();
c.Platform = string.Join("|",srz.Deserialize<string[]>(j));
break;
default:
if (!c.BuildSettings.TryDeserializeBuildSetting(j))
j.Skip();
break;
}
}
}
return c;
}
示例10: ReadJson
//EXAMPLE:
// "r": [
// {
// "$reql_type$": "GROUPED_DATA",
// "data": [
// [
// "Alice",
// [
// { "id": 5, "player": "Alice", "points": 7, "type": "free"},
// { "id": 12, "player": "Alice", "points": 2, "type": "free" }
// ]
// ],
// [
// "Bob",
// [
// { "id": 2, "player": "Bob", "points": 15, "type": "ranked" },
// { "id": 11, "player": "Bob", "points": 10, "type": "free" }
// ]
// ]
// ]
// }
// ]
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
reader.ReadAndAssertProperty(Converter.PseudoTypeKey);
var reql_type = reader.ReadAsString();
if( reql_type != Converter.GroupedData )
{
throw new JsonSerializationException($"Expected {Converter.PseudoTypeKey} should be {Converter.GroupedData} but got {reql_type}.");
}
reader.ReadAndAssertProperty("data");
//move reader to property value
reader.ReadAndAssert();
//... probably find a better way to do this.
var listType = typeof(List<>).MakeGenericType(objectType);
var list = (IList)Activator.CreateInstance(listType);
var data = serializer.Deserialize<List<JArray>>(reader);
foreach( var group in data )
{
var key = group[0]; //key, group value in common
var items = group[1]; //the grouped items
var grouping = Activator.CreateInstance(objectType, key, items);
list.Add(grouping);
}
//.Select(arr => Activator.CreateInstance(objectType, arr) ).ToList();
return list;
}
示例11: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.String)
{
return new AssemblyName(reader.ReadAsString());
}
return null;
}
示例12: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
{
var result = new TwitterRateLimitStatusSummary();
reader.Read();
reader.Read();
reader.Read();
result.AccessToken = reader.ReadAsString(); // access_token
return result;
}
示例13: ReadJson
public override object ReadJson(
JsonReader reader,
Type objectType,
object existingValue,
JsonSerializer serializer)
{
var webColorString = reader.ReadAsString();
return new WebColor(webColorString);
}
示例14: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var s = reader.ReadAsString();
switch(s)
{
case "keep": return ReindexRouting.Keep;
case "discard": return ReindexRouting.Discard;
default: return new ReindexRouting(s);
}
}
示例15: 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;
}