Serialize Tweetinvi using JsonConvert.SerializeObject



我正在尝试使以下代码正常工作,但是当我尝试序列化对象时会抛出未实现的异常。它指出"方法或操作未实现"。我尝试将 ITweet 实现为具体类,但我无法从接口转到具体类。

private void SendToKinesis(ITweet tweet)
    {

        var dataAsJson = JsonConvert.SerializeObject(tweet);
        byte[] dataAsBytes = Encoding.UTF8.GetBytes(dataAsJson);
       //Send to Kinesis
    }

完全例外:

System.NotImplementException:未实现该方法或操作。 at Tweetinvi.Logic.JsonConverters.JsonPropertyConverterRepository.WriteJson(JsonWriter writer, Object value, JsonSerializer serializer) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeConvertable(JsonWriter writer, JsonConverter converter, Object value, JsonContract contract, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType) at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType) at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value, Type objectType) at Newtonsoft.Json.JsonConvert.SerializeObjectInternal在 TwitterIngestion 中发生了类型为"System.NotSupportedException"的第一次机会异常.exe(对象值,类型类型,JsonSerializer jsonSerializer) at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.SerializeObject(Object value) at TwitterIngestion.IngestionService.SendToKinesis(ITweet tweet) in c:\Users\sepehr500\Desktop\Work Stuff\TwitterIngestion\TwitterIngestion\IngestionTask.cs:line 104

尝试以下代码:

private void SendToKinesis(ITweet tweet)
{

    var dataAsJson = JsonConvert.SerializeObject<ITweet>(tweet);
    byte[] dataAsBytes = Encoding.UTF8.GetBytes(dataAsJson);
   //Send to Kinesis
}

相关内容

  • 没有找到相关文章

最新更新