|
- using System;
- using System.Collections.Generic;
- using System.Formats.Asn1;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Newtonsoft.Json;
-
- namespace GpsCardGatewayPosition.Common.Helper
- {
- public class StringJsonConvert : JsonConverter
- {
- public override bool CanConvert(Type objectType)
- {
- return objectType == typeof(string);
- }
-
- public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
- {
- if (reader.TokenType == JsonToken.String)
- {
- return reader.Value;
- }
-
- if (reader.TokenType == JsonToken.StartArray)
- {
- //舍弃[]之间的所有内容
- do
- {
- var temp = reader.Read();
- } while (reader.TokenType != JsonToken.EndArray);
- }
- else if (reader.TokenType == JsonToken.StartObject)
- {
- //舍弃{}之间的所有内容
- do
- {
- reader.Read();
- } while (reader.TokenType != JsonToken.EndObject);
- }
- return null;
- }
-
- public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
- {
- writer.WriteValue(value.ToString());
- }
- }
- }
|